moxml 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3d9ee4016fae355b5533b22d992f4a127e788b1a39cef001458c3085133f42d
4
- data.tar.gz: 79c85ee71c8def65d684cf1243d44871a9120260ec505d48341ef0b96eaa31e0
3
+ metadata.gz: c46c9d241e38351b1547ab8be8297ff2902886f022ccdfb3fc2f196d2594bf2b
4
+ data.tar.gz: b1d34fb4306d96d940afea932d5d9f6c6bcffc74c6715e00a6f622302be2f878
5
5
  SHA512:
6
- metadata.gz: fda8c13b2491e63200ed771dd85cd29fa15a7bc297583fe8c33b8d9ad8b93b05b4dca29d253d798397c37d3b72304d0588d5f11c95de6e16aba74ea26472cdbb
7
- data.tar.gz: d1853370b28eee67a4df08cd4b4bdbc83816866282f731eeca15870da119ff1e643898db823d49ee5e98ae1bcfc34370672b29e38abc5ccab542088bb239e3d9
6
+ metadata.gz: 9178c13199c195aa0b3ed628d5837fa6c1fdaeaa3e3cc462a8520a89ad6bb98963ff0a9c2b668038ff27a0653e2aa2fba98ce1c8bc10eccc74abab0daa26e455
7
+ data.tar.gz: 5b1b06dea56ac0b28dd2b8ca072fa554039936c336e6b262430d40f45ab2972b1e6bf38f3c13cf192c9fc2a9cc9fe827abc99aa662d30ebdaae97d361d981475
@@ -16,7 +16,7 @@ module Moxml
16
16
  def on_element(element, output)
17
17
  name = element.expanded_name
18
18
 
19
- attrs = ""
19
+ attrs = []
20
20
  element.attributes.each do |attr|
21
21
  attrs << " "
22
22
  on_attribute(attr, attrs)
@@ -28,7 +28,7 @@ module Moxml
28
28
  ">"
29
29
  end
30
30
 
31
- output << "<#{name}#{attrs}#{closing_tag}"
31
+ output << "<#{name}#{attrs.join}#{closing_tag}"
32
32
  end
33
33
 
34
34
  def on_namespace_definition(ns, output)
@@ -479,7 +479,7 @@ module Moxml
479
479
 
480
480
  if should_include_decl && !node.xml_declaration && !has_existing_declaration
481
481
  # Need to add declaration - create default one
482
- output = +""
482
+ output = []
483
483
  output << '<?xml version="1.0" encoding="UTF-8"?>'
484
484
  output << "\n"
485
485
 
@@ -491,10 +491,10 @@ module Moxml
491
491
  output << ::Moxml::Adapter::CustomizedOga::XmlGenerator.new(child).to_xml
492
492
  end
493
493
 
494
- return output
494
+ return output.join
495
495
  elsif !should_include_decl
496
496
  # Skip xml_declaration
497
- output = +""
497
+ output = []
498
498
 
499
499
  # Serialize doctype if present
500
500
  output << node.doctype.to_xml << "\n" if node.doctype
@@ -506,7 +506,7 @@ module Moxml
506
506
  output << ::Moxml::Adapter::CustomizedOga::XmlGenerator.new(child).to_xml
507
507
  end
508
508
 
509
- return output
509
+ return output.join
510
510
  end
511
511
  end
512
512
 
@@ -514,19 +514,20 @@ module Moxml
514
514
  # But first check if we need to handle declaration specially
515
515
  if node.is_a?(::Oga::XML::Document) && node.xml_declaration
516
516
  # Document has declaration - use custom handling to avoid duplicates
517
- output = +""
517
+ output = []
518
+ xml_declaration_serialized = false
518
519
 
519
520
  # Serialize children, but skip XmlDeclaration if it would cause duplication
520
521
  node.children.each do |child|
521
- # Check if this would cause duplication by seeing if we already have one in output
522
- if child.is_a?(::Oga::XML::XmlDeclaration) && output.include?("<?xml")
523
- next # Skip duplicate declaration
524
- end
522
+ xml_declaration = child.is_a?(::Oga::XML::XmlDeclaration)
523
+ next if xml_declaration && xml_declaration_serialized
524
+
525
+ xml_declaration_serialized = true if xml_declaration
525
526
 
526
527
  output << ::Moxml::Adapter::CustomizedOga::XmlGenerator.new(child).to_xml
527
528
  end
528
529
 
529
- output
530
+ output.join
530
531
  else
531
532
  # Normal case - use XmlGenerator directly
532
533
  ::Moxml::Adapter::CustomizedOga::XmlGenerator.new(node).to_xml
data/lib/moxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.14"
5
5
  end
@@ -12,6 +12,22 @@ RSpec.describe Moxml::Adapter::Oga do
12
12
 
13
13
  it_behaves_like "xml adapter"
14
14
 
15
+ describe "serialization" do
16
+ it "does not duplicate XML declarations when declaration nodes repeat" do
17
+ context = Moxml::Context.new(:oga)
18
+ doc = context.create_document
19
+
20
+ doc.add_child(doc.create_declaration("1.0", "UTF-8"))
21
+ doc.add_child(doc.create_declaration("1.0", "UTF-8"))
22
+ doc.add_child(doc.create_element("root"))
23
+
24
+ serialized = doc.to_xml
25
+
26
+ expect(serialized.scan("<?xml").size).to eq(1)
27
+ expect(serialized).to include("<root></root>")
28
+ end
29
+ end
30
+
15
31
  describe "entity handling" do
16
32
  it "preserves non-breaking space through parse and serialize round-trip" do
17
33
  xml = "<root>Item&nbsp;One</root>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.