Skip to content

Commit

Permalink
Don't mutate strings
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Sep 14, 2023
1 parent 3a39cdf commit 4fbfd36
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/multi_xml/parsers/libxml2_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def node_to_hash(node, hash = {}) # rubocop:disable Metrics/AbcSize, Metrics/Cyc
if c.element?
node_to_hash(c, node_hash)
elsif c.text? || c.cdata?
node_hash[MultiXml::CONTENT_ROOT] << c.content
node_hash[MultiXml::CONTENT_ROOT] += c.content
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/multi_xml/parsers/oga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def node_to_hash(node, hash = {}) # rubocop:disable Metrics/AbcSize, Metrics/Cyc
if c.is_a?(::Oga::XML::Element)
node_to_hash(c, node_hash)
elsif c.is_a?(::Oga::XML::Text) || c.is_a?(::Oga::XML::Cdata)
node_hash[MultiXml::CONTENT_ROOT] << c.text
node_hash[MultiXml::CONTENT_ROOT] += c.text
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/multi_xml/parsers/rexml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def collapse(element)
def merge_texts!(hash, element)
if element.has_text?
# must use value to prevent double-escaping
texts = ""
element.texts.each { |t| texts << t.value }
texts = element.texts.map(&:value).join
merge!(hash, MultiXml::CONTENT_ROOT, texts)
else
hash
Expand Down

0 comments on commit 4fbfd36

Please sign in to comment.