moxml 0.5.148 → 0.5.149

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/nightly-fuzz.yml +80 -0
  3. data/docs/_pages/divergences.adoc +58 -0
  4. data/docs/_references/processing-model.adoc +30 -3
  5. data/lib/compat/opal/moxml_boot.rb +4 -0
  6. data/lib/moxml/adapter/leptris.rb +110 -19
  7. data/lib/moxml/adapter/libxml.rb +145 -23
  8. data/lib/moxml/adapter/oga.rb +33 -3
  9. data/lib/moxml/adapter/ox.rb +26 -2
  10. data/lib/moxml/adapter/rexml.rb +65 -15
  11. data/lib/moxml/context.rb +5 -1
  12. data/lib/moxml/document.rb +6 -6
  13. data/lib/moxml/node.rb +22 -6
  14. data/lib/moxml/node_set.rb +11 -0
  15. data/lib/moxml/reference/normalizer.rb +63 -0
  16. data/lib/moxml/reference/parser.rb +417 -0
  17. data/lib/moxml/reference/writer.rb +121 -0
  18. data/lib/moxml/reference.rb +205 -0
  19. data/lib/moxml/version.rb +1 -1
  20. data/lib/moxml/xpath/compiler.rb +17 -2
  21. data/lib/moxml/xpath/ordering.rb +97 -0
  22. data/lib/moxml/xpath.rb +1 -0
  23. data/lib/moxml.rb +1 -0
  24. data/spec/consistency/adapter_parity_spec.rb +2 -0
  25. data/spec/consistency/differential_taxonomy_spec.rb +117 -0
  26. data/spec/consistency/divergence_register_spec.rb +9 -1
  27. data/spec/consistency/eol_normalization_spec.rb +2 -0
  28. data/spec/consistency/loud_degradation_spec.rb +2 -0
  29. data/spec/consistency/metamorphic_properties_spec.rb +195 -0
  30. data/spec/consistency/metamorphic_spec.rb +138 -0
  31. data/spec/consistency/model_coverage_audit_spec.rb +108 -0
  32. data/spec/consistency/reference_differential_spec.rb +186 -0
  33. data/spec/consistency/xpath_idioms_spec.rb +11 -0
  34. data/spec/consistency/xslt_spec.rb +2 -0
  35. data/spec/moxml/adapter/leptris_attribute_snapshot_spec.rb +10 -7
  36. data/spec/moxml/adapter/ox_spec.rb +1 -1
  37. data/spec/moxml/attribute_resolver_spec.rb +2 -0
  38. data/spec/moxml/c14n/adapter_delegation_spec.rb +2 -0
  39. data/spec/moxml/doctype_spec.rb +7 -0
  40. data/spec/moxml/document_parse_diagnostics_spec.rb +2 -0
  41. data/spec/moxml/entity_spec.rb +2 -0
  42. data/spec/moxml/plan_conformance_spec.rb +2 -0
  43. data/spec/moxml/processing_instruction_spec.rb +9 -0
  44. data/spec/moxml/reference_opal_spec.rb +29 -0
  45. data/spec/moxml/reference_spec.rb +162 -0
  46. data/spec/moxml/sax_spec.rb +2 -0
  47. data/spec/moxml/text_spec.rb +2 -0
  48. data/spec/moxml/to_html_spec.rb +2 -0
  49. data/spec/moxml/xhtml_output_spec.rb +2 -0
  50. data/spec/moxml/xpath/axes_spec.rb +2 -2
  51. data/spec/moxml/xsd_spec.rb +38 -0
  52. data/spec/support/input_generator.rb +154 -0
  53. data/spec/support/input_taxonomy.rb +212 -0
  54. data/spec/support/xml_generator.rb +54 -0
  55. metadata +16 -1
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The canonical input-class taxonomy (TODO.sota/01-totality): every
4
+ # class of input the processing model touches, as shared fixture data
5
+ # the differential suites consume. Adding a class here automatically
6
+ # extends the whole-class differential; a class without a stable
7
+ # cross-adapter answer must cite a registered divergence (D-ID) or a
8
+ # named raise in the consuming suite.
9
+ module InputTaxonomy
10
+ Input = Struct.new(:id, :klass, :xml, :well_formed, :note) do
11
+ def well_formed? = well_formed
12
+ end
13
+
14
+ WELL_FORMED = "well-formed"
15
+ MALFORMED = "malformed"
16
+
17
+ def self.all
18
+ @all ||= inputs.freeze
19
+ end
20
+
21
+ def self.well_formed
22
+ all.select(&:well_formed?)
23
+ end
24
+
25
+ def self.malformed
26
+ all.reject(&:well_formed?)
27
+ end
28
+
29
+ def self.by_klass(klass)
30
+ all.select { |i| i.klass == klass }
31
+ end
32
+
33
+ CLASSES = [
34
+ "empty/minimal",
35
+ "deep nesting",
36
+ "huge text/attributes",
37
+ "entities",
38
+ "namespaces",
39
+ "mixed content",
40
+ "pi/comment/cdata edges",
41
+ "malformed",
42
+ ].freeze
43
+
44
+ # Registered per-input exemptions for the cross-adapter
45
+ # differential: input id => { face => { adapter => D-NN } }. The
46
+ # values are register IDs (docs/_pages/divergences.adoc) enforced
47
+ # by the coverage audit.
48
+ EXEMPT = {
49
+ "mixed content: whitespace runs" => {
50
+ nodes: { ox: "D-13", headed_ox: "D-13" },
51
+ text: { ox: "D-13", headed_ox: "D-13" },
52
+ },
53
+ "mixed content: CRLF text normalizes to LF" => {
54
+ text: { oga: "D-02" },
55
+ },
56
+ "mixed content: bare CR text normalizes to LF" => {
57
+ text: { oga: "D-02" },
58
+ },
59
+ "mixed content: character-ref CR survives" => {
60
+ text: { oga: "D-02", ox: "D-03", headed_ox: "D-03" },
61
+ },
62
+ "pi/comment/cdata: pi inside content" => {
63
+ text: { oga: "D-14" },
64
+ pi_content: { ox: "D-05", headed_ox: "D-05" },
65
+ },
66
+ "pi/comment/cdata: pi multi-space separator" => {
67
+ text: { oga: "D-14" },
68
+ pi_content: { ox: "D-05", headed_ox: "D-05" },
69
+ },
70
+ "huge text with entities" => {
71
+ text: { rexml: "D-16" },
72
+ serialize: { rexml: "D-16" },
73
+ },
74
+ "pi/comment/cdata: pi before root" => {
75
+ nodes: { rexml: "D-15" },
76
+ text: { rexml: "D-15" },
77
+ pi_content: { ox: "D-05", headed_ox: "D-05" },
78
+ },
79
+ "pi/comment/cdata: comment before and after root" => {
80
+ comment_content: { ox: "D-06", headed_ox: "D-06" },
81
+ },
82
+ "pi/comment/cdata: comment inside content" => {
83
+ comment_content: { ox: "D-06", headed_ox: "D-06" },
84
+ },
85
+ }.freeze
86
+
87
+ # Engines whose strict lane cannot see a class of malformedness are
88
+ # registered: oga's strict is lexer-strict, not well-formedness-
89
+ # strict (D-17). leptris raises through the facade guard (D-18,
90
+ # leptris-ruby#514) and is therefore verified, not exempt; entity
91
+ # and prefix classes are engine-variant by design (entity modes,
92
+ # namespace validation).
93
+ STRICT_EXEMPT = {
94
+ "malformed: bad nesting" => { oga: "D-17" },
95
+ "malformed: invalid utf-8 byte" => { oga: "D-18", ox: "D-18",
96
+ headed_ox: "D-18" },
97
+ }.freeze
98
+
99
+ def self.inputs
100
+ [
101
+ # -- empty/minimal --
102
+ Input.new("empty/minimal: empty string", "empty/minimal", "", false,
103
+ "no root: parse must fail loudly or per contract"),
104
+ Input.new("empty/minimal: whitespace only", "empty/minimal", " \n\t ", false,
105
+ "whitespace-only: no root"),
106
+ Input.new("empty/minimal: bare root", "empty/minimal", "<r/>", true, nil),
107
+ Input.new("empty/minimal: empty paired root", "empty/minimal", "<r></r>", true, nil),
108
+ Input.new("empty/minimal: declaration only", "empty/minimal",
109
+ '<?xml version="1.0"?>', false, "declaration without root"),
110
+
111
+ # -- deep nesting --
112
+ Input.new("deep nesting: 200 levels", "deep nesting",
113
+ "<r>#{'<d>' * 200}leaf#{'</d>' * 200}</r>", true, nil),
114
+ Input.new("deep nesting: siblings at depth", "deep nesting",
115
+ "<r>#{'<a><b>' * 50}#{'</b></a>' * 50}</r>", true, nil),
116
+
117
+ # -- huge text/attributes --
118
+ Input.new("huge text: 100k chars", "huge text/attributes",
119
+ "<r>#{'x' * 100_000}</r>", true, nil),
120
+ Input.new("huge attribute: 10k chars", "huge text/attributes",
121
+ %(<r a="#{'y' * 10_000}"/>), true, nil),
122
+ Input.new("huge text with entities", "huge text/attributes",
123
+ "<r>#{'&amp;' * 20_000}</r>", true, nil),
124
+
125
+ # -- entities: built-in --
126
+ Input.new("entities: all five built-ins", "entities",
127
+ "<r>&amp;&lt;&gt;&quot;&apos;</r>", true, nil),
128
+ # -- entities: numeric --
129
+ Input.new("entities: decimal numeric", "entities",
130
+ "<r>&#65;&#233;</r>", true, nil),
131
+ Input.new("entities: hex numeric", "entities",
132
+ "<r>&#x41;&#xE9;</r>", true, nil),
133
+ # -- entities: custom (DTD-declared) --
134
+ Input.new("entities: custom DTD entity", "entities",
135
+ '<!DOCTYPE r [<!ENTITY x "expanded">]><r>&x;</r>', true, nil),
136
+ # -- entities: undefined (disabled context) --
137
+ Input.new("entities: undefined reference", "entities",
138
+ "<r>&undefinedEntity;</r>", false,
139
+ "undefined entity: malformed without a DTD"),
140
+ Input.new("entities: NBSP char ref", "entities",
141
+ "<r>&#160;</r>", true, "U+00A0 survives as content"),
142
+
143
+ # -- namespaces: default --
144
+ Input.new("namespaces: default", "namespaces",
145
+ '<r xmlns="urn:a"><c/></r>', true, nil),
146
+ # -- namespaces: prefixed --
147
+ Input.new("namespaces: prefixed", "namespaces",
148
+ '<r xmlns:p="urn:a"><p:c/></r>', true, nil),
149
+ # -- namespaces: undeclared prefix --
150
+ Input.new("namespaces: undeclared prefix", "namespaces",
151
+ "<p:c/>", false,
152
+ "undeclared prefix: malformed in strict parsing"),
153
+ # -- namespaces: redeclared --
154
+ Input.new("namespaces: redeclared", "namespaces",
155
+ '<r xmlns:p="urn:a"><s xmlns:p="urn:b"><p:c/></s></r>', true, nil),
156
+ # -- namespaces: reserved xml --
157
+ Input.new("namespaces: reserved xml prefix", "namespaces",
158
+ '<r xml:lang="en"/>', true, nil),
159
+ # -- namespaces: xmlns attribute --
160
+ Input.new("namespaces: xmlns declaration attribute", "namespaces",
161
+ '<r xmlns="urn:a" xmlns:p="urn:b"/>', true, nil),
162
+
163
+ # -- mixed content --
164
+ Input.new("mixed content: text and inline", "mixed content",
165
+ "<r>text <b>bold</b> tail</r>", true, nil),
166
+ Input.new("mixed content: whitespace runs", "mixed content",
167
+ "<r>\n <b>x</b>\n <b>y</b>\n</r>", true, nil),
168
+ Input.new("mixed content: attribute entities in text", "mixed content",
169
+ '<r a="&lt;&amp;">&lt;tag&gt;</r>', true, nil),
170
+ Input.new("mixed content: CRLF text normalizes to LF", "mixed content",
171
+ "<r>a\r\nb</r>", true, "XML 1.0 §2.11"),
172
+ Input.new("mixed content: bare CR text normalizes to LF", "mixed content",
173
+ "<r>a\rb</r>", true, "XML 1.0 §2.11"),
174
+ Input.new("mixed content: character-ref CR survives", "mixed content",
175
+ "<r>a&#xD;b</r>", true, "&#xD; is not normalized"),
176
+
177
+ # -- pi/comment/cdata edges --
178
+ Input.new("pi/comment/cdata: pi before root", "pi/comment/cdata edges",
179
+ '<?xml-stylesheet href="a"?> <r/>', true, nil),
180
+ Input.new("pi/comment/cdata: comment before and after root", "pi/comment/cdata edges",
181
+ "<!-- lead --><r/><!-- trail -->", true, nil),
182
+ Input.new("pi/comment/cdata: cdata with markup", "pi/comment/cdata edges",
183
+ "<r><![CDATA[<notmarkup> & raw]]></r>", true, nil),
184
+ Input.new("pi/comment/cdata: empty cdata", "pi/comment/cdata edges",
185
+ "<r><![CDATA[]]></r>", true, nil),
186
+ Input.new("pi/comment/cdata: comment inside content", "pi/comment/cdata edges",
187
+ "<r>a<!-- mid -->b</r>", true, nil),
188
+ Input.new("pi/comment/cdata: pi inside content", "pi/comment/cdata edges",
189
+ "<r>a<?pi data?>b</r>", true,
190
+ "PI content must not contribute to text (D-14 on oga)"),
191
+ Input.new("pi/comment/cdata: pi multi-space separator", "pi/comment/cdata edges",
192
+ "<r><?pi data?></r>", true,
193
+ "separator whitespace is not PI content (uniform)"),
194
+ Input.new("pi/comment/cdata: empty pi", "pi/comment/cdata edges",
195
+ "<r><?pi?></r>", true, nil),
196
+
197
+ # -- malformed: unclosed --
198
+ Input.new("malformed: unclosed element", "malformed", "<r><c>", false, nil),
199
+ # -- malformed: bad nest --
200
+ Input.new("malformed: bad nesting", "malformed", "<r><a><b></a></b></r>", false, nil),
201
+ # -- malformed: bad attribute --
202
+ Input.new("malformed: unterminated attribute", "malformed",
203
+ '<r a="x>', false, nil),
204
+ # -- malformed: stray closing --
205
+ Input.new("malformed: stray closing tag", "malformed", "</r>", false, nil),
206
+ # -- malformed: invalid encoding bytes --
207
+ Input.new("malformed: invalid utf-8 byte", "malformed",
208
+ "<r>\xC3\x28</r>", false,
209
+ "0xC3 0x28 is not valid UTF-8"),
210
+ ].freeze
211
+ end
212
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Seeded XML generator (TODO.sota/02): composes random
4
+ # taxonomy-class documents — elements, text, attributes, namespaces,
5
+ # comments, PIs, CDATA — deterministic per seed. The metamorphic
6
+ # suite runs its properties over generated docs; a failing seed is a
7
+ # reproducible regression.
8
+ module XmlGenerator
9
+ ELEMENT_NAMES = %w[r a b node item entry rec child leaf].freeze
10
+ ATTR_NAMES = %w[id name kind type ref value flag].freeze
11
+ TEXT_POOL = [
12
+ "plain text", "text with spaces ", "entities &amp; &lt;tags&gt;",
13
+ "unicode déjà vu", "numbers 12345", "", " ", "tail "
14
+ ].freeze
15
+ PI_TARGETS = %w[render probe].freeze
16
+
17
+ module_function
18
+
19
+ # Deterministic RNG: Ruby's Mersenne with an explicit seed.
20
+ def generate(seed)
21
+ rng = Random.new(seed)
22
+ depth = rng.rand(1..5)
23
+ body = compose(rng, depth)
24
+ %(<root#{attrs(rng, depth)}>#{body}</root>)
25
+ end
26
+
27
+ def compose(rng, depth)
28
+ parts = []
29
+ rng.rand(1..4).times do
30
+ case rng.rand(depth.zero? ? 5 : 10)
31
+ when 0..4 then parts << element(rng, depth)
32
+ when 5 then parts << TEXT_POOL.sample(random: rng)
33
+ when 6 then parts << "<!-- #{format('%04x', rng.rand(65_536))} -->"
34
+ when 7 then parts << "<?#{PI_TARGETS.sample(random: rng)} d#{format('%02x', rng.rand(256))}?>"
35
+ when 8 then parts << "<![CDATA[raw #{format('%04x', rng.rand(65_536))} <stuff>]]>"
36
+ when 9 then parts << format("<e n=\"%d\"/>", rng.rand(100))
37
+ end
38
+ end
39
+ parts.join
40
+ end
41
+
42
+ def element(rng, depth)
43
+ name = ELEMENT_NAMES.sample(random: rng)
44
+ ns = rng.rand(4).zero? ? %( xmlns="urn:g#{rng.rand(3)}") : ""
45
+ body = depth.positive? ? compose(rng, depth - 1) : TEXT_POOL.sample(random: rng)
46
+ "<#{name}#{ns}#{attrs(rng, depth)}>#{body}</#{name}>"
47
+ end
48
+
49
+ def attrs(rng, _depth)
50
+ (0...rng.rand(0..3)).map do |i|
51
+ %( #{ATTR_NAMES.sample(random: rng)}#{i}="v#{rng.rand(100)}")
52
+ end.join
53
+ end
54
+ end
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.5.148
4
+ version: 0.5.149
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -24,6 +24,7 @@ files:
24
24
  - ".github/workflows/dependent-repos.json"
25
25
  - ".github/workflows/dependent-tests.yml"
26
26
  - ".github/workflows/docs.yml"
27
+ - ".github/workflows/nightly-fuzz.yml"
27
28
  - ".github/workflows/opal.yml"
28
29
  - ".github/workflows/rake.yml"
29
30
  - ".github/workflows/release.yml"
@@ -227,6 +228,10 @@ files:
227
228
  - lib/moxml/node_set.rb
228
229
  - lib/moxml/plan.rb
229
230
  - lib/moxml/processing_instruction.rb
231
+ - lib/moxml/reference.rb
232
+ - lib/moxml/reference/normalizer.rb
233
+ - lib/moxml/reference/parser.rb
234
+ - lib/moxml/reference/writer.rb
230
235
  - lib/moxml/sax.rb
231
236
  - lib/moxml/sax/block_handler.rb
232
237
  - lib/moxml/sax/element_handler.rb
@@ -297,6 +302,7 @@ files:
297
302
  - lib/moxml/xpath/engine.rb
298
303
  - lib/moxml/xpath/errors.rb
299
304
  - lib/moxml/xpath/lexer.rb
305
+ - lib/moxml/xpath/ordering.rb
300
306
  - lib/moxml/xpath/parser.rb
301
307
  - lib/moxml/xpath/ruby/generator.rb
302
308
  - lib/moxml/xpath/ruby/node.rb
@@ -312,12 +318,16 @@ files:
312
318
  - sig/moxml.rbs
313
319
  - spec/consistency/README.md
314
320
  - spec/consistency/adapter_parity_spec.rb
321
+ - spec/consistency/differential_taxonomy_spec.rb
315
322
  - spec/consistency/divergence_register_spec.rb
316
323
  - spec/consistency/document_text_spec.rb
317
324
  - spec/consistency/eol_normalization_spec.rb
318
325
  - spec/consistency/html_doctype_spec.rb
319
326
  - spec/consistency/loud_degradation_spec.rb
327
+ - spec/consistency/metamorphic_properties_spec.rb
328
+ - spec/consistency/metamorphic_spec.rb
320
329
  - spec/consistency/model_coverage_audit_spec.rb
330
+ - spec/consistency/reference_differential_spec.rb
321
331
  - spec/consistency/round_trip_spec.rb
322
332
  - spec/consistency/spec_constant_uniqueness_spec.rb
323
333
  - spec/consistency/xpath_idioms_spec.rb
@@ -548,6 +558,8 @@ files:
548
558
  - spec/moxml/processing_instruction_spec.rb
549
559
  - spec/moxml/readonly_parse_spec.rb
550
560
  - spec/moxml/recover_mode_spec.rb
561
+ - spec/moxml/reference_opal_spec.rb
562
+ - spec/moxml/reference_spec.rb
551
563
  - spec/moxml/sax/namespace_splitter_spec.rb
552
564
  - spec/moxml/sax_entity_parity_spec.rb
553
565
  - spec/moxml/sax_spec.rb
@@ -609,8 +621,11 @@ files:
609
621
  - spec/performance/xpath_benchmark_spec.rb
610
622
  - spec/spec_helper.rb
611
623
  - spec/support/allocation_helper.rb
624
+ - spec/support/input_generator.rb
625
+ - spec/support/input_taxonomy.rb
612
626
  - spec/support/opal.rb
613
627
  - spec/support/w3c_namespace_helpers.rb
628
+ - spec/support/xml_generator.rb
614
629
  - spec/support/xml_matchers.rb
615
630
  - spec/unit/rexml_isolated_test.rb
616
631
  homepage: https://github.com/lutaml/moxml