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 +4 -4
- data/lib/moxml/adapter/customized_oga/xml_generator.rb +2 -2
- data/lib/moxml/adapter/oga.rb +11 -10
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/adapter/oga_spec.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c46c9d241e38351b1547ab8be8297ff2902886f022ccdfb3fc2f196d2594bf2b
|
|
4
|
+
data.tar.gz: b1d34fb4306d96d940afea932d5d9f6c6bcffc74c6715e00a6f622302be2f878
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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)
|
data/lib/moxml/adapter/oga.rb
CHANGED
|
@@ -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
|
-
|
|
522
|
-
if
|
|
523
|
-
|
|
524
|
-
|
|
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
|
@@ -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 One</root>"
|