moxml 0.5.147 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/nightly-fuzz.yml +80 -0
- data/docs/_pages/divergences.adoc +58 -0
- data/docs/_references/processing-model.adoc +30 -3
- data/lib/compat/opal/moxml_boot.rb +4 -0
- data/lib/moxml/adapter/leptris.rb +180 -20
- data/lib/moxml/adapter/libxml.rb +145 -23
- data/lib/moxml/adapter/oga.rb +33 -3
- data/lib/moxml/adapter/ox.rb +26 -2
- data/lib/moxml/adapter/rexml.rb +65 -15
- data/lib/moxml/context.rb +5 -1
- data/lib/moxml/document.rb +24 -10
- data/lib/moxml/node.rb +34 -6
- data/lib/moxml/node_set.rb +11 -0
- data/lib/moxml/reference/normalizer.rb +63 -0
- data/lib/moxml/reference/parser.rb +417 -0
- data/lib/moxml/reference/writer.rb +121 -0
- data/lib/moxml/reference.rb +205 -0
- data/lib/moxml/version.rb +1 -1
- data/lib/moxml/xpath/compiler.rb +17 -2
- data/lib/moxml/xpath/ordering.rb +97 -0
- data/lib/moxml/xpath.rb +1 -0
- data/lib/moxml.rb +1 -0
- data/spec/consistency/adapter_parity_spec.rb +2 -0
- data/spec/consistency/differential_taxonomy_spec.rb +117 -0
- data/spec/consistency/divergence_register_spec.rb +9 -1
- data/spec/consistency/eol_normalization_spec.rb +2 -0
- data/spec/consistency/loud_degradation_spec.rb +2 -0
- data/spec/consistency/metamorphic_properties_spec.rb +195 -0
- data/spec/consistency/metamorphic_spec.rb +138 -0
- data/spec/consistency/model_coverage_audit_spec.rb +108 -0
- data/spec/consistency/reference_differential_spec.rb +186 -0
- data/spec/consistency/xpath_idioms_spec.rb +11 -0
- data/spec/consistency/xslt_spec.rb +2 -0
- data/spec/moxml/adapter/leptris_attribute_snapshot_spec.rb +10 -7
- data/spec/moxml/adapter/leptris_contract_reads_spec.rb +29 -0
- data/spec/moxml/adapter/leptris_detached_text_spec.rb +10 -3
- data/spec/moxml/adapter/leptris_parse_lint_spec.rb +12 -0
- data/spec/moxml/adapter/ox_spec.rb +1 -1
- data/spec/moxml/attribute_resolver_spec.rb +2 -0
- data/spec/moxml/c14n/adapter_delegation_spec.rb +2 -0
- data/spec/moxml/doctype_spec.rb +7 -0
- data/spec/moxml/document_parse_diagnostics_spec.rb +2 -0
- data/spec/moxml/entity_spec.rb +2 -0
- data/spec/moxml/plan_conformance_spec.rb +2 -0
- data/spec/moxml/processing_instruction_spec.rb +9 -0
- data/spec/moxml/reference_opal_spec.rb +29 -0
- data/spec/moxml/reference_spec.rb +162 -0
- data/spec/moxml/sax_spec.rb +2 -0
- data/spec/moxml/text_spec.rb +2 -0
- data/spec/moxml/to_html_spec.rb +2 -0
- data/spec/moxml/xhtml_output_spec.rb +2 -0
- data/spec/moxml/xpath/axes_spec.rb +2 -2
- data/spec/moxml/xsd_spec.rb +38 -0
- data/spec/support/input_generator.rb +154 -0
- data/spec/support/input_taxonomy.rb +212 -0
- data/spec/support/xml_generator.rb +54 -0
- metadata +17 -2
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Seeded XML input generator (TODO.sota/02): composes the 01
|
|
4
|
+
# taxonomy's vocabulary into fresh inputs, deterministically from a
|
|
5
|
+
# seed. CI legs run a fixed seed — identical cases every run; the
|
|
6
|
+
# nightly fuzz leg passes a random one (MOXML_FUZZ_SEED). Every case
|
|
7
|
+
# id carries its provenance ("gen <seed>/<i> <malform>"), so a
|
|
8
|
+
# failure reproduces at that seed and index.
|
|
9
|
+
module InputGenerator
|
|
10
|
+
# Generated inputs record the divergence-relevant features they use
|
|
11
|
+
# so the differential exempts exactly those cells, never silently —
|
|
12
|
+
# every value is a register ID (docs/_pages/divergences.adoc).
|
|
13
|
+
FEATURE_EXEMPT = {
|
|
14
|
+
inter_element_ws: {
|
|
15
|
+
nodes: { ox: "D-13", headed_ox: "D-13" },
|
|
16
|
+
text: { ox: "D-13", headed_ox: "D-13" },
|
|
17
|
+
},
|
|
18
|
+
pi_in_content: { text: { oga: "D-14" } },
|
|
19
|
+
pre_root_ws: { nodes: { rexml: "D-15" }, text: { rexml: "D-15" } },
|
|
20
|
+
adjacent_cdata: {
|
|
21
|
+
nodes: { oga: "D-19", rexml: "D-19", ox: "D-19", headed_ox: "D-19",
|
|
22
|
+
leptris: "D-19" },
|
|
23
|
+
},
|
|
24
|
+
}.freeze
|
|
25
|
+
|
|
26
|
+
# malform is one of the three guaranteed-breaking structural
|
|
27
|
+
# mutations; oga's strict lane is lexer-strict (D-17) and is
|
|
28
|
+
# exempted for all of them in the strict-raise property.
|
|
29
|
+
Case = Struct.new(:id, :xml, :well_formed, :features, :voids, :malform)
|
|
30
|
+
|
|
31
|
+
ELEMENTS = %w[a b sec p].freeze
|
|
32
|
+
VOIDS = %w[br img hr].freeze
|
|
33
|
+
ATTR_VALUES = [
|
|
34
|
+
"1", "x y", "a & b", "<tag>", "AB", "taillé"
|
|
35
|
+
].freeze
|
|
36
|
+
TEXTS = [
|
|
37
|
+
"plain text", " spaced ", "a & b < c", "AB",
|
|
38
|
+
"café   NBSP", "word"
|
|
39
|
+
].freeze
|
|
40
|
+
NAMESPACES = [
|
|
41
|
+
'xmlns="urn:t"', 'xmlns:ns="urn:n"', 'xmlns="urn:r"'
|
|
42
|
+
].freeze
|
|
43
|
+
XML_ATTRS = ['xml:space="preserve"', 'xml:lang="en"'].freeze
|
|
44
|
+
MALFORMS = %i[unclosed stray attr_quote].freeze
|
|
45
|
+
|
|
46
|
+
module_function
|
|
47
|
+
|
|
48
|
+
# mode: :fuzz mixes the three structural malformations into roughly
|
|
49
|
+
# a third of the cases (the strict-raise property consumes those);
|
|
50
|
+
# :well_formed answers pure compositions.
|
|
51
|
+
def cases(seed:, count:, mode: :fuzz)
|
|
52
|
+
rng = Random.new(seed)
|
|
53
|
+
Array.new(count) do |i|
|
|
54
|
+
body, features, voids = compose(rng)
|
|
55
|
+
id = "gen #{seed}/#{i}"
|
|
56
|
+
if mode == :fuzz && rng.rand(3).zero?
|
|
57
|
+
malform = MALFORMS[rng.rand(MALFORMS.length)]
|
|
58
|
+
Case.new("#{id} #{malform}", mutate(body, malform), false,
|
|
59
|
+
features, voids, malform)
|
|
60
|
+
else
|
|
61
|
+
Case.new(id, body, true, features, voids, nil)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def compose(rng)
|
|
67
|
+
features = []
|
|
68
|
+
voids = []
|
|
69
|
+
pre = +""
|
|
70
|
+
draw = rng.rand(6)
|
|
71
|
+
if draw.zero?
|
|
72
|
+
pre << "<!--pre-root-->"
|
|
73
|
+
elsif draw == 1
|
|
74
|
+
pre << "<?prep root?>"
|
|
75
|
+
elsif draw == 2
|
|
76
|
+
pre << " "
|
|
77
|
+
features << :pre_root_ws
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
attrs = +'<r id="root"'
|
|
81
|
+
attrs << " #{NAMESPACES[rng.rand(NAMESPACES.length)]}" if rng.rand(2).zero?
|
|
82
|
+
attrs << " #{XML_ATTRS[rng.rand(XML_ATTRS.length)]}" if rng.rand(3).zero?
|
|
83
|
+
attrs << ' ns:x="v"' if rng.rand(3).zero?
|
|
84
|
+
attrs << ">"
|
|
85
|
+
|
|
86
|
+
body = +""
|
|
87
|
+
depth = 1 + rng.rand(4)
|
|
88
|
+
(1 + rng.rand(4)).times { body << child(rng, 0, depth, features, voids) }
|
|
89
|
+
# a whitespace-only run between two constructs is a dropped-text
|
|
90
|
+
# divergence cell (D-13 on ox/headed_ox)
|
|
91
|
+
features << :inter_element_ws if body.match?(%r{>\s+<})
|
|
92
|
+
|
|
93
|
+
xml = "#{pre}#{attrs}#{body}</r>"
|
|
94
|
+
# a default-namespace declaration scopes XPath name tests away
|
|
95
|
+
# from generated a/b elements (XPath 1.0, processing model
|
|
96
|
+
# "Names and namespaces")
|
|
97
|
+
features << :default_ns if xml.include?('xmlns="')
|
|
98
|
+
# adjacent text-like leaves — CDATA next to CDATA/text — coalesce
|
|
99
|
+
# on the libxml2 lane (D-19)
|
|
100
|
+
if xml.match?(/]\]>\s*<!\[CDATA\[/) || xml.match?(/]\]>\s*[^<\s]/) ||
|
|
101
|
+
xml.match?(/[^<\s]\s*<!\[CDATA\[/)
|
|
102
|
+
features << :adjacent_cdata
|
|
103
|
+
end
|
|
104
|
+
[xml, features.uniq, voids.uniq]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def child(rng, level, max_depth, features, voids)
|
|
108
|
+
if level < max_depth && rng.rand(8) < 5
|
|
109
|
+
inner = +""
|
|
110
|
+
(1 + rng.rand(3)).times do
|
|
111
|
+
inner << child(rng, level + 1, max_depth, features, voids)
|
|
112
|
+
end
|
|
113
|
+
name = ELEMENTS[rng.rand(ELEMENTS.length)]
|
|
114
|
+
extra = +""
|
|
115
|
+
extra << " #{NAMESPACES[rng.rand(NAMESPACES.length)]}" if rng.rand(4).zero?
|
|
116
|
+
extra << " #{XML_ATTRS[rng.rand(XML_ATTRS.length)]}" if rng.rand(4).zero?
|
|
117
|
+
extra << " ns:x=\"#{ATTR_VALUES[rng.rand(ATTR_VALUES.length)]}\"" if rng.rand(3).zero?
|
|
118
|
+
"<#{name}#{extra}>#{inner}</#{name}>"
|
|
119
|
+
else
|
|
120
|
+
leaf(rng, features, voids)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def leaf(rng, features, voids)
|
|
125
|
+
case rng.rand(6)
|
|
126
|
+
when 0, 1
|
|
127
|
+
TEXTS[rng.rand(TEXTS.length)]
|
|
128
|
+
when 2
|
|
129
|
+
"<!--comment #{rng.rand(9)}-->"
|
|
130
|
+
when 3
|
|
131
|
+
features << :pi_in_content
|
|
132
|
+
"<?inst data-#{rng.rand(9)}?>"
|
|
133
|
+
when 4
|
|
134
|
+
"<![CDATA[x < #{rng.rand(9)} & more]]>"
|
|
135
|
+
else
|
|
136
|
+
v = VOIDS[rng.rand(VOIDS.length)]
|
|
137
|
+
voids << v
|
|
138
|
+
"<#{v}/>"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Each mutation is guaranteed to break well-formedness (the root
|
|
143
|
+
# close and the root id attribute always exist in composed bodies).
|
|
144
|
+
def mutate(xml, malform)
|
|
145
|
+
case malform
|
|
146
|
+
when :unclosed
|
|
147
|
+
xml.sub(%r{</[a-z]+>}, "")
|
|
148
|
+
when :stray
|
|
149
|
+
"#{xml}</r>"
|
|
150
|
+
when :attr_quote
|
|
151
|
+
xml.sub('id="root"', 'id="root')
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -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>#{'&' * 20_000}</r>", true, nil),
|
|
124
|
+
|
|
125
|
+
# -- entities: built-in --
|
|
126
|
+
Input.new("entities: all five built-ins", "entities",
|
|
127
|
+
"<r>&<>"'</r>", true, nil),
|
|
128
|
+
# -- entities: numeric --
|
|
129
|
+
Input.new("entities: decimal numeric", "entities",
|
|
130
|
+
"<r>Aé</r>", true, nil),
|
|
131
|
+
Input.new("entities: hex numeric", "entities",
|
|
132
|
+
"<r>Aé</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> </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="<&"><tag></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
b</r>", true, "
 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 & <tags>",
|
|
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,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moxml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.149
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
Moxml is a unified XML manipulation library that provides a common API
|
|
@@ -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
|