Skip to content

Handle new "No root element" error from REXML#85

Merged
kiskoza merged 1 commit intomasterfrom
rexml-3-4-3
Sep 19, 2025
Merged

Handle new "No root element" error from REXML#85
kiskoza merged 1 commit intomasterfrom
rexml-3-4-3

Conversation

@kiskoza
Copy link
Copy Markdown
Collaborator

@kiskoza kiskoza commented Sep 19, 2025

Closes #84

Comment on lines 234 to 240
def self.parse(xml)
parser.parse(xml)
rescue REXML::ParseException => e
return {} if e.message.match?(/^Malformed XML: No root element/)

raise e
end
Copy link
Copy Markdown

@mattwd7 mattwd7 Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems kinda brittle – if the error message changes, this will require update again. I think instead we want to get ahead of this error if the error-provoking conditions are met, e.g.

Suggested change
def self.parse(xml)
parser.parse(xml)
rescue REXML::ParseException => e
return {} if e.message.match?(/^Malformed XML: No root element/)
raise e
end
def self.parse(xml)
return {} if xml.blank?
parser.parse(xml)
end

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately blank? is not pure Ruby, it's coming from ActiveSupport. xml.strip == '' should do fine, wdyt?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm 🙂

@kiskoza kiskoza merged commit 3eb3c70 into master Sep 19, 2025
34 checks passed
@kiskoza kiskoza deleted the rexml-3-4-3 branch September 22, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rexml 3.4.3 causes test failures

2 participants