diff --git a/lib/multi_xml/parsers/libxml2_parser.rb b/lib/multi_xml/parsers/libxml2_parser.rb index 348d684..158b1ee 100644 --- a/lib/multi_xml/parsers/libxml2_parser.rb +++ b/lib/multi_xml/parsers/libxml2_parser.rb @@ -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 diff --git a/lib/multi_xml/parsers/oga.rb b/lib/multi_xml/parsers/oga.rb index 0c78f7f..bc52ec7 100644 --- a/lib/multi_xml/parsers/oga.rb +++ b/lib/multi_xml/parsers/oga.rb @@ -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 diff --git a/lib/multi_xml/parsers/rexml.rb b/lib/multi_xml/parsers/rexml.rb index d06f921..2c09fea 100644 --- a/lib/multi_xml/parsers/rexml.rb +++ b/lib/multi_xml/parsers/rexml.rb @@ -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