Skip to content

Handle the case when XML is empty

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA

What does this MR do and why?

Issue: #268035 (closed)

There is a problem with Gitlab::XmlConverter that we recently introduced in !148779 (merged): if the XML string is empty, an error will be reported.

Currently MR fixes this problem.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

# Before
[1] Gitlab::XmlConverter.new('')
NoMethodError: undefined method `to_hash` for nil:NilClass
from /Users/deer/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/activesupport-7.0.8.1/lib/active_support/xml_mini/nokogiri.rb:36:in `to_hash`

# After
[1] pry(main)> Gitlab::XmlConverter.new('')
=> #<Gitlab::XmlConverter:0x0000000299adf6b0>
[2] pry(main)> Gitlab::XmlConverter.new('').to_h
=> nil
Edited by Zhiyuan Lu

Merge request reports