lutaml-model 0.8.166 → 0.8.167
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/downstream-performance.yml +5 -0
- data/Gemfile +1 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/native_emission.rb +210 -70
- data/lib/lutaml/xml/model_transform.rb +22 -0
- data/lib/lutaml/xml/serialization/instance_methods.rb +8 -0
- data/spec/lutaml/xml/leptris/native_emission_nested_sharing_spec.rb +152 -0
- data/spec/lutaml/xml/leptris/native_emission_ns_parity_spec.rb +26 -13
- data/spec/lutaml/xml/schema/xsd/schema_xmlns_declarations_spec.rb +87 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e6fcc4e9c561155b0b5b78a09ee81e231f66c581d3b34668c8baa3e15e21aea2
|
|
4
|
+
data.tar.gz: be9b8132335d16b9c187b73f70f7daa9844be7c27cf6b40a3906178f7d377945
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd3a488a8ef78f804f7e1c06fa076d3fb751a670849ac9aecad20131c2b997af3c98246ee80a6728d83d0d571aa0715b85c1b7b44fba08ff4f9ffc864fa24f33
|
|
7
|
+
data.tar.gz: 4236bfee9b6d9a5eb7d50efa5c700599cca6321c1938ce6f3399df16b13f0bc7ee54927fc66743bb636a275c1157073586e74f1f3dd26790af70093c9c649bc4
|
|
@@ -180,6 +180,11 @@ jobs:
|
|
|
180
180
|
needs: benchmark
|
|
181
181
|
runs-on: ubuntu-latest
|
|
182
182
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
183
|
+
# The baseline PR step pushes with the job's GITHUB_TOKEN; the
|
|
184
|
+
# workflow default is contents:read, so without this grant the
|
|
185
|
+
# create-pull-request push 403s on every main push (#1128).
|
|
186
|
+
permissions:
|
|
187
|
+
contents: write
|
|
183
188
|
steps:
|
|
184
189
|
# persist-credentials: false — checkout's persisted Authorization
|
|
185
190
|
# extraheader collides with create-pull-request's own token on the
|
data/Gemfile
CHANGED
|
@@ -49,7 +49,7 @@ gem "rexml"
|
|
|
49
49
|
# exact-URI attribute rows, nested-attribute capture, wildcard rows,
|
|
50
50
|
# walk-side ns retention and leniency, :unqualified rows, and the
|
|
51
51
|
# address-based text attach all ride it.
|
|
52
|
-
gem "leptris", ">= 1.9.
|
|
52
|
+
gem "leptris", ">= 1.9.407.0" # RAW op (leptris#1941) + the attr ns_prefix deep-copy fix (leptris#1967/#1968): the emission lane gates engines below 1.9.407 to the DOM lane
|
|
53
53
|
gem "teptris"
|
|
54
54
|
gem "yeptris" unless Gem.win_platform?
|
|
55
55
|
# TODO: revert rng branch to main when lutaml/rng#32 is merged
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -64,16 +64,69 @@ module Lutaml
|
|
|
64
64
|
ffi.const_defined?(:PLAN_OP_RAW)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
# The engine's attr-row ns_prefix deep-copy fix rides
|
|
68
|
+
# 1.9.407.0 (leptris#1967, fixed by leptris#1968): earlier
|
|
69
|
+
# engines keep the binding's freed FFI anchor pointer in the
|
|
70
|
+
# built plan and read freed heap bytes at serialize time —
|
|
71
|
+
# garbage prefixes (CT_RPr:val) and empty output (the
|
|
72
|
+
# lutaml-model#1126 uniword signatures). There is no
|
|
73
|
+
# capability constant to probe for a pure bugfix release, so
|
|
74
|
+
# the gate reads the binding version. Namespace-less trees
|
|
75
|
+
# never consult the descriptor's ns rows and stay on the
|
|
76
|
+
# lane regardless.
|
|
77
|
+
def engine_ns_prefix_safe?(version = ::Leptris::VERSION)
|
|
78
|
+
Gem::Version.new(version.to_s) >=
|
|
79
|
+
Gem::Version.new("1.9.407.0")
|
|
80
|
+
rescue ArgumentError
|
|
81
|
+
false
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Whether any tree in the emission graph carries an EXACT
|
|
85
|
+
# namespace Hash (tree, attribute rows, or child rows,
|
|
86
|
+
# recursively through nested plans) — the rows whose
|
|
87
|
+
# ns_prefix the pre-1.9.407 engine fails to retain.
|
|
88
|
+
def namespaced_tree?(tree)
|
|
89
|
+
return false unless tree.is_a?(::Hash)
|
|
90
|
+
|
|
91
|
+
return true if tree[:ns].is_a?(::Hash)
|
|
92
|
+
return true if (tree[:attributes] || []).any? do |a|
|
|
93
|
+
a[:ns].is_a?(::Hash)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
(tree[:children] || []).any? do |r|
|
|
97
|
+
next true if r[:ns].is_a?(::Hash)
|
|
98
|
+
next false unless r[:kind] == :nested && r[:plan]
|
|
99
|
+
|
|
100
|
+
namespaced_tree?(r[:plan])
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
67
104
|
# plan: the compiled plan; instance: the emitting instance.
|
|
68
105
|
# A nil instance runs the static checks only.
|
|
69
106
|
def compatible?(plan, instance = nil, register = nil)
|
|
70
107
|
return false if plan.nil?
|
|
71
108
|
return false unless raw_op_supported?
|
|
72
|
-
return false
|
|
109
|
+
return false if namespaced_tree?(plan[:tree]) &&
|
|
110
|
+
!engine_ns_prefix_safe?
|
|
111
|
+
return false unless ordered_ns_emittable?(plan, instance)
|
|
73
112
|
return false if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
74
113
|
instance.element_order.nil?
|
|
75
114
|
|
|
76
|
-
subtree_gate_ok?(plan, instance, register
|
|
115
|
+
subtree_gate_ok?(plan, instance, register,
|
|
116
|
+
prefixed_source?(instance))
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Prefixed spelling is only faithful when the ROOT instance
|
|
120
|
+
# preserves a prefixed source: the DOM lane inherits the
|
|
121
|
+
# root's prefix spelling down the tree (nested children
|
|
122
|
+
# spell through the hoisted prefix), so one root-level fact
|
|
123
|
+
# governs every EXACT row in the emission graph. Constructed
|
|
124
|
+
# and default-parsed roots pin the default-xmlns form,
|
|
125
|
+
# which the ops lane cannot express (uniword bold/custprops
|
|
126
|
+
# format regressions when admitted).
|
|
127
|
+
def prefixed_source?(instance)
|
|
128
|
+
instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
129
|
+
!instance.xml_namespace_prefix.to_s.empty?
|
|
77
130
|
end
|
|
78
131
|
|
|
79
132
|
# The emission graph is a DAG: Descriptor.flatten_plan
|
|
@@ -100,10 +153,21 @@ module Lutaml
|
|
|
100
153
|
end
|
|
101
154
|
|
|
102
155
|
# A plan whose tree defers subtrees verbatim (:raw rows —
|
|
103
|
-
# ordered children, e.g. uniword's document → body)
|
|
156
|
+
# ordered children, e.g. uniword's document → body), at any
|
|
157
|
+
# depth. The DEFERRED rows of NESTED descendants defer too:
|
|
158
|
+
# an unordered root whose grandchildren defer (uniword
|
|
159
|
+
# clrScheme → color → ordered srgbClr) must ride the
|
|
160
|
+
# emission descriptor + identity graph — ops against the
|
|
161
|
+
# parse descriptor reference child plans the compiled tree
|
|
162
|
+
# never materialized (:raw rows carry no plan), and the
|
|
163
|
+
# engine rejects the program (INVALID_ARG, -5) or cross-
|
|
164
|
+
# wires subtree slots.
|
|
104
165
|
def deferred_rows?(tree)
|
|
105
166
|
(tree[:children] || []).any? do |r|
|
|
106
|
-
DEFERRED_ROW_KINDS.include?(r[:kind])
|
|
167
|
+
next true if DEFERRED_ROW_KINDS.include?(r[:kind])
|
|
168
|
+
next false unless r[:kind] == :nested && r[:plan]
|
|
169
|
+
|
|
170
|
+
deferred_rows?(r[:plan])
|
|
107
171
|
end
|
|
108
172
|
end
|
|
109
173
|
|
|
@@ -114,7 +178,10 @@ module Lutaml
|
|
|
114
178
|
# instance must carry a pristine parse-built element_order
|
|
115
179
|
# with Element/Text entries only (comments and PIs keep the
|
|
116
180
|
# DOM lane; mutation reroutes through the reconciler).
|
|
117
|
-
def subtree_gate_ok?(plan, instance, register
|
|
181
|
+
def subtree_gate_ok?(plan, instance, register,
|
|
182
|
+
prefixed_source = nil)
|
|
183
|
+
prefixed_source = prefixed_source?(instance) if
|
|
184
|
+
prefixed_source.nil?
|
|
118
185
|
return false unless plan[:rows].all? do |row|
|
|
119
186
|
gate_row_kind?(row, register)
|
|
120
187
|
end
|
|
@@ -148,8 +215,16 @@ module Lutaml
|
|
|
148
215
|
child_plan = child_type.is_a?(Class) &&
|
|
149
216
|
PlanCompiler.compile(child_type, register)
|
|
150
217
|
return false unless child_plan
|
|
218
|
+
# The ns gate is per-tree and per-instance: a
|
|
219
|
+
# namespace-less parent can nest namespaced children
|
|
220
|
+
# whose EXACT rows would still spell prefix:local,
|
|
221
|
+
# and each child preserves (or not) its own source
|
|
222
|
+
# prefix.
|
|
223
|
+
return false unless ordered_ns_emittable?(child_plan,
|
|
224
|
+
prefixed_source)
|
|
151
225
|
return false unless subtree_gate_ok?(child_plan, item,
|
|
152
|
-
register
|
|
226
|
+
register,
|
|
227
|
+
prefixed_source)
|
|
153
228
|
end
|
|
154
229
|
end
|
|
155
230
|
true
|
|
@@ -182,26 +257,43 @@ module Lutaml
|
|
|
182
257
|
# emits text; wildcards bail in subtree_gate_ok?), so the
|
|
183
258
|
# check covers the tree ns, attribute rows, and the
|
|
184
259
|
# named-element rows only.
|
|
185
|
-
def ordered_ns_emittable?(plan)
|
|
260
|
+
def ordered_ns_emittable?(plan, instance_or_flag = nil)
|
|
261
|
+
flag = if instance_or_flag.is_a?(::Lutaml::Model::Serialize)
|
|
262
|
+
prefixed_source?(instance_or_flag)
|
|
263
|
+
else
|
|
264
|
+
instance_or_flag
|
|
265
|
+
end
|
|
186
266
|
tree = plan[:tree]
|
|
187
|
-
return false unless ns_emittable?(tree[:ns])
|
|
267
|
+
return false unless ns_emittable?(tree[:ns], flag)
|
|
188
268
|
return false if (tree[:attributes] || []).any? do |a|
|
|
189
|
-
!ns_emittable?(a[:ns])
|
|
269
|
+
!ns_emittable?(a[:ns], flag)
|
|
190
270
|
end
|
|
191
271
|
|
|
192
272
|
(tree[:children] || []).all? do |row|
|
|
193
273
|
next true unless NS_EMITTABLE_ROW_KINDS.include?(row[:kind])
|
|
194
274
|
|
|
195
|
-
ns_emittable?(row[:ns])
|
|
275
|
+
ns_emittable?(row[:ns], flag)
|
|
196
276
|
end
|
|
197
277
|
end
|
|
198
278
|
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
279
|
+
# Only two shapes ride the ops lane:
|
|
280
|
+
# - nil (:none) and :unqualified — the unwritten local
|
|
281
|
+
# spelling, nothing to declare;
|
|
282
|
+
# - EXACT Hash forms, but ONLY under a prefixed-preserved
|
|
283
|
+
# root. The engine's plan serializer spells prefix:local
|
|
284
|
+
# for every EXACT row and cannot express the default-xmlns
|
|
285
|
+
# form — so admitting constructed or default-parsed
|
|
286
|
+
# instances flipped the pinned output format (uniword
|
|
287
|
+
# bold `<b xmlns=...>` and custprops `<property>`
|
|
288
|
+
# regressions). A prefixed-parsed root pins the prefixed
|
|
289
|
+
# form itself — Priority 1 format preservation — and the
|
|
290
|
+
# ops spelling matches it, inherited down the tree.
|
|
291
|
+
def ns_emittable?(ns_form, prefixed_source = nil)
|
|
292
|
+
return true if ns_form.nil? || ns_form == :unqualified
|
|
293
|
+
return false unless ns_form.is_a?(Hash) && ns_form[:prefix] &&
|
|
294
|
+
!ns_form[:prefix].empty?
|
|
295
|
+
|
|
296
|
+
prefixed_source ? true : false
|
|
205
297
|
end
|
|
206
298
|
|
|
207
299
|
# len is the logical length of the buffer: slots [base, len) hold
|
|
@@ -215,6 +307,8 @@ module Lutaml
|
|
|
215
307
|
buf = (Thread.current[OP_BUFFER_KEY] ||= [])
|
|
216
308
|
base = (Thread.current[OP_BUFFER_BASE_KEY] ||= 0)
|
|
217
309
|
len = base
|
|
310
|
+
result = nil
|
|
311
|
+
bailed = false
|
|
218
312
|
begin
|
|
219
313
|
op_slot(buf, len)
|
|
220
314
|
buf[len][:kind] = :element
|
|
@@ -230,20 +324,36 @@ module Lutaml
|
|
|
230
324
|
emit_element(buf, len + 1, instance, plan, register,
|
|
231
325
|
root_index, graph)
|
|
232
326
|
end
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
327
|
+
# A nil walk means the bail signal (a valued cycle-point
|
|
328
|
+
# row the ops lane cannot spell — #1130): reset the
|
|
329
|
+
# buffer tail and hand the instance back to the caller's
|
|
330
|
+
# DOM-lane fallback. The ensure's trim uses the last
|
|
331
|
+
# known-good length.
|
|
332
|
+
if len.nil?
|
|
333
|
+
bailed = true
|
|
334
|
+
len = base
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
unless bailed
|
|
338
|
+
op_slot(buf, len)
|
|
339
|
+
buf[len][:kind] = :end
|
|
340
|
+
len += 1
|
|
341
|
+
d = if emission_lane?(plan, instance)
|
|
342
|
+
emission_descriptor_for(plan, register)
|
|
343
|
+
else
|
|
344
|
+
plan[:descriptor]
|
|
345
|
+
end
|
|
346
|
+
compact = d.serialize(d.build_result(buf[base, len - base]))
|
|
347
|
+
result = ::Leptris::XML.parse(compact).to_xml(indent: 2,
|
|
348
|
+
no_decl: true)
|
|
349
|
+
end
|
|
243
350
|
ensure
|
|
244
351
|
buf.slice!(len..) if buf.size > len
|
|
245
352
|
Thread.current[OP_BUFFER_BASE_KEY] = base
|
|
246
353
|
end
|
|
354
|
+
return nil if bailed
|
|
355
|
+
|
|
356
|
+
result
|
|
247
357
|
end
|
|
248
358
|
|
|
249
359
|
# The emission graph is needed when the plan replays an
|
|
@@ -402,7 +512,7 @@ module Lutaml
|
|
|
402
512
|
end
|
|
403
513
|
next unless entry
|
|
404
514
|
|
|
405
|
-
|
|
515
|
+
rule, attr, kind, _spelling, delegate, _row_ns,
|
|
406
516
|
row_index = entry
|
|
407
517
|
value = value_of(instance, attr, delegate)
|
|
408
518
|
case kind
|
|
@@ -433,7 +543,7 @@ module Lutaml
|
|
|
433
543
|
tree = emission_tree_for(child_plan, register)
|
|
434
544
|
graph[tree]
|
|
435
545
|
else
|
|
436
|
-
|
|
546
|
+
compiled_graph_for(plan)[child_plan[:tree]]
|
|
437
547
|
end
|
|
438
548
|
next unless child_index
|
|
439
549
|
|
|
@@ -449,9 +559,36 @@ module Lutaml
|
|
|
449
559
|
emit_element(buf, len, item, child_plan, register,
|
|
450
560
|
child_index, graph)
|
|
451
561
|
end
|
|
562
|
+
return nil if len.nil?
|
|
563
|
+
|
|
452
564
|
op_slot(buf, len)
|
|
453
565
|
buf[len][:kind] = :end
|
|
454
566
|
len += 1
|
|
567
|
+
when :child_deferred
|
|
568
|
+
# Valued cycle-point rows splice the child's own
|
|
569
|
+
# serialization verbatim under the SAME name-match
|
|
570
|
+
# guard as the unordered lane. Without this case
|
|
571
|
+
# the ordered replay silently dropped the subtree
|
|
572
|
+
# (the <b:Author/> empty-shell loss,
|
|
573
|
+
# lutaml-model#1130: Author's self-referential row
|
|
574
|
+
# is a cycle point INSIDE an ordered plan).
|
|
575
|
+
Array(value).each do |item|
|
|
576
|
+
next unless item
|
|
577
|
+
|
|
578
|
+
root = item.class.mappings_for(:xml, register)
|
|
579
|
+
&.root_element
|
|
580
|
+
return nil if root.nil? || root.to_s != rule.name.to_s
|
|
581
|
+
|
|
582
|
+
fragment = serialize_fragment(item, register)
|
|
583
|
+
return nil if fragment.nil?
|
|
584
|
+
next if fragment.empty?
|
|
585
|
+
|
|
586
|
+
op_slot(buf, len)
|
|
587
|
+
buf[len][:kind] = :raw
|
|
588
|
+
buf[len][:plan_index] = my_index
|
|
589
|
+
buf[len][:value] = fragment
|
|
590
|
+
len += 1
|
|
591
|
+
end
|
|
455
592
|
when :scalar
|
|
456
593
|
len = scalar_op(buf, len, my_index, row_index, attr,
|
|
457
594
|
value, register)
|
|
@@ -499,7 +636,6 @@ module Lutaml
|
|
|
499
636
|
def emit_element(buf, len, instance, plan, register, plan_index,
|
|
500
637
|
graph = nil)
|
|
501
638
|
my_index = plan_index
|
|
502
|
-
layout = flat_layout_for(plan, register)
|
|
503
639
|
|
|
504
640
|
len = emit_attributes(buf, len, instance, plan, my_index, register)
|
|
505
641
|
|
|
@@ -531,12 +667,24 @@ module Lutaml
|
|
|
531
667
|
# the child model through its own best lane (the plan
|
|
532
668
|
# serializer — native or DOM) and splices the fragment
|
|
533
669
|
# verbatim through the RAW op; the empty value emits
|
|
534
|
-
# nothing (the DOM lane's rule).
|
|
670
|
+
# nothing (the DOM lane's rule). The splice serves
|
|
671
|
+
# only children whose own root element IS the row's
|
|
672
|
+
# wire name — type-only models and role wrappers
|
|
673
|
+
# (b:Performer wrapping an Author-typed value) need
|
|
674
|
+
# the parent's row-name wrapping, which only the
|
|
675
|
+
# interpretive writer performs — so anything else
|
|
676
|
+
# bails the lane (the DOM ordered lane bails on
|
|
677
|
+
# valued cycle points identically).
|
|
535
678
|
Array(value).each do |item|
|
|
536
679
|
next unless item
|
|
537
680
|
|
|
681
|
+
root = item.class.mappings_for(:xml, register)
|
|
682
|
+
&.root_element
|
|
683
|
+
return nil if root.nil? || root.to_s != rule.name.to_s
|
|
684
|
+
|
|
538
685
|
fragment = serialize_fragment(item, register)
|
|
539
|
-
|
|
686
|
+
return nil if fragment.nil?
|
|
687
|
+
next if fragment.empty?
|
|
540
688
|
|
|
541
689
|
op_slot(buf, len)
|
|
542
690
|
buf[len][:kind] = :raw
|
|
@@ -569,7 +717,7 @@ module Lutaml
|
|
|
569
717
|
tree = emission_tree_for(child_plan, register)
|
|
570
718
|
graph[tree]
|
|
571
719
|
else
|
|
572
|
-
|
|
720
|
+
compiled_graph_for(plan)[child_plan[:tree]]
|
|
573
721
|
end
|
|
574
722
|
next unless child_index
|
|
575
723
|
|
|
@@ -585,6 +733,8 @@ module Lutaml
|
|
|
585
733
|
emit_element(buf, len, item, child_plan,
|
|
586
734
|
register, child_index, graph)
|
|
587
735
|
end
|
|
736
|
+
return nil if len.nil?
|
|
737
|
+
|
|
588
738
|
op_slot(buf, len)
|
|
589
739
|
buf[len][:kind] = :end
|
|
590
740
|
len += 1
|
|
@@ -608,44 +758,34 @@ module Lutaml
|
|
|
608
758
|
out || item.to_xml
|
|
609
759
|
end
|
|
610
760
|
|
|
611
|
-
#
|
|
612
|
-
#
|
|
613
|
-
#
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
layout[i] = [row[:plan], rel]
|
|
640
|
-
rel += subtree_size(row[:plan])
|
|
641
|
-
end
|
|
642
|
-
layout
|
|
643
|
-
|
|
644
|
-
end
|
|
645
|
-
|
|
646
|
-
def subtree_size(tree)
|
|
647
|
-
1 + (tree[:children] || []).sum do |row|
|
|
648
|
-
row[:kind] == :nested && row[:plan] ? subtree_size(row[:plan]) : 0
|
|
761
|
+
# Mirror of Descriptor.flatten_plan numbering over the
|
|
762
|
+
# COMPILED tree: pre-order, identity-deduped — the same
|
|
763
|
+
# plan_index space leptris_plan_build assigns when building
|
|
764
|
+
# plan[:descriptor]. The per-parent relative-offset layout
|
|
765
|
+
# this replaces agreed with the engine only at depth 0 on
|
|
766
|
+
# share-free trees: nested emission passed raw offsets as
|
|
767
|
+
# absolute indices (uniword clrScheme cross-wired dk1/sysClr
|
|
768
|
+
# onto accent2's slots → INVALID_ARG -5), and shared child
|
|
769
|
+
# plans (one SysClr tree under twelve color rows) make
|
|
770
|
+
# per-parent pre-order diverge from the engine's deduped
|
|
771
|
+
# numbering entirely.
|
|
772
|
+
def compiled_graph_for(plan)
|
|
773
|
+
plan[:compiled_graph] ||= begin
|
|
774
|
+
map = {}.compare_by_identity
|
|
775
|
+
counter = [0]
|
|
776
|
+
walk = lambda do |tree|
|
|
777
|
+
next map[tree] if map.key?(tree)
|
|
778
|
+
|
|
779
|
+
idx = counter[0]
|
|
780
|
+
counter[0] += 1
|
|
781
|
+
map[tree] = idx
|
|
782
|
+
(tree[:children] || []).each do |r|
|
|
783
|
+
walk.call(r[:plan]) if r[:kind] == :nested && r[:plan]
|
|
784
|
+
end
|
|
785
|
+
idx
|
|
786
|
+
end
|
|
787
|
+
walk.call(plan[:tree])
|
|
788
|
+
map
|
|
649
789
|
end
|
|
650
790
|
end
|
|
651
791
|
|
|
@@ -322,6 +322,7 @@ module Lutaml
|
|
|
322
322
|
mixed_content_option, xml_mapping,
|
|
323
323
|
instance_is_serialize)
|
|
324
324
|
set_schema_location(instance, doc, xml_mapping, effective_register)
|
|
325
|
+
set_root_namespaces(instance, doc)
|
|
325
326
|
|
|
326
327
|
defaults_used = []
|
|
327
328
|
|
|
@@ -620,6 +621,27 @@ instance_is_serialize = nil)
|
|
|
620
621
|
instance.raw_schema_location = schema_location.value
|
|
621
622
|
end
|
|
622
623
|
|
|
624
|
+
# Retain the document element's own xmlns declarations on the
|
|
625
|
+
# instance (#1131): prefix → URI, with the default xmlns under
|
|
626
|
+
# the nil key. Qualified QNames (xs:element/@ref, xsi:type,
|
|
627
|
+
# identity-constraint xpath) resolve exactly against the
|
|
628
|
+
# prefixes the document actually declared — the declaration
|
|
629
|
+
# plan's registry is URI-keyed and planner-derived, so it
|
|
630
|
+
# collapses documents that bind several prefixes to one URI.
|
|
631
|
+
def set_root_namespaces(instance, doc)
|
|
632
|
+
return unless instance.is_a?(Lutaml::Model::Serialize)
|
|
633
|
+
|
|
634
|
+
root = doc.is_a?(::Lutaml::Xml::Document) ? doc.root : doc
|
|
635
|
+
own = root&.own_namespaces
|
|
636
|
+
return if own.nil? || own.empty?
|
|
637
|
+
|
|
638
|
+
declarations = {}
|
|
639
|
+
own.each do |prefix, ns_data|
|
|
640
|
+
declarations[prefix] = ns_data.uri
|
|
641
|
+
end
|
|
642
|
+
instance.xmlns_declarations = declarations.freeze
|
|
643
|
+
end
|
|
644
|
+
|
|
623
645
|
def apply_processing_instruction_deserialization(doc, instance, xml_mapping,
|
|
624
646
|
_effective_register)
|
|
625
647
|
pi_mappings = xml_mapping.processing_instruction_mappings
|
|
@@ -24,6 +24,13 @@ module Lutaml
|
|
|
24
24
|
# Released after plan is built to allow GC of the DOM tree.
|
|
25
25
|
attr_accessor :pending_plan_root_element
|
|
26
26
|
|
|
27
|
+
# The parsed document element's own xmlns declarations, keyed by
|
|
28
|
+
# prefix (the default xmlns sits under the nil key). Captured at
|
|
29
|
+
# deserialization so qualified QNames — xs:element/@ref,
|
|
30
|
+
# xsi:type, identity-constraint xpath — resolve exactly against
|
|
31
|
+
# the prefixes the document actually declared (#1131).
|
|
32
|
+
attr_accessor :xmlns_declarations
|
|
33
|
+
|
|
27
34
|
# Clear all internal XML parse state on this instance.
|
|
28
35
|
#
|
|
29
36
|
# Call before re-serializing a previously-parsed instance when the
|
|
@@ -202,6 +209,7 @@ module Lutaml
|
|
|
202
209
|
# Extend INTERNAL_ATTRIBUTES with XML-specific ones
|
|
203
210
|
def pretty_print_instance_variables
|
|
204
211
|
xml_internals = %i[@import_declaration_plan @pending_plan_root_element
|
|
212
|
+
@xmlns_declarations
|
|
205
213
|
@__xml_namespace_prefix
|
|
206
214
|
@__xml_ns_prefixes @__xml_original_namespace_uri
|
|
207
215
|
@xml_declaration @raw_schema_location]
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The uniword clrScheme class of shape: an UNORDERED root whose
|
|
4
|
+
# grandchildren defer (each color choice carries an ORDERED srgbClr
|
|
5
|
+
# child beside a shared sysClr nested child). Two ways this broke the
|
|
6
|
+
# native emission lane before the graph-numbering fix:
|
|
7
|
+
#
|
|
8
|
+
# - ops against the parse descriptor referenced child plans the
|
|
9
|
+
# compiled tree never materialized (:raw rows carry no plan) — the
|
|
10
|
+
# engine rejected the program (plan result build, INVALID_ARG -5);
|
|
11
|
+
# - the per-parent relative-offset layout crossed depth boundaries,
|
|
12
|
+
# sending children of later rows onto earlier rows' plan slots
|
|
13
|
+
# (accent2's slot carrying dk1's sysClr).
|
|
14
|
+
#
|
|
15
|
+
# The shared SysColor plan (one compiled tree under every color row —
|
|
16
|
+
# the [class, register] compile cache) pins the identity-deduped
|
|
17
|
+
# numbering both halves depend on.
|
|
18
|
+
|
|
19
|
+
require "lutaml/model"
|
|
20
|
+
require "lutaml/xml/leptris"
|
|
21
|
+
|
|
22
|
+
RSpec.describe "native emission with nested deferral and shared plans" do
|
|
23
|
+
let(:theme_ns) do
|
|
24
|
+
Class.new(Lutaml::Xml::Namespace) do
|
|
25
|
+
uri "http://example.com/theme"
|
|
26
|
+
prefix_default "a"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
let(:sys_color_class) do
|
|
31
|
+
ns = theme_ns
|
|
32
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
33
|
+
attribute :val, :string
|
|
34
|
+
attribute :last_clr, :string
|
|
35
|
+
|
|
36
|
+
xml do
|
|
37
|
+
namespace ns
|
|
38
|
+
element "sysClr"
|
|
39
|
+
map_attribute "val", to: :val
|
|
40
|
+
map_attribute "lastClr", to: :last_clr
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
stub_const("ClrScheme::SysColor", klass)
|
|
44
|
+
klass
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
let(:srgb_color_class) do
|
|
48
|
+
ns = theme_ns
|
|
49
|
+
sys = sys_color_class
|
|
50
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
51
|
+
attribute :val, :string
|
|
52
|
+
attribute :sys, sys
|
|
53
|
+
|
|
54
|
+
xml do
|
|
55
|
+
namespace ns
|
|
56
|
+
ordered
|
|
57
|
+
element "srgbClr"
|
|
58
|
+
map_attribute "val", to: :val
|
|
59
|
+
map_element "sysClr", to: :sys
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
stub_const("ClrScheme::SrgbColor", klass)
|
|
63
|
+
klass
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
let(:color_class) do
|
|
67
|
+
ns = theme_ns
|
|
68
|
+
srgb = srgb_color_class
|
|
69
|
+
sys = sys_color_class
|
|
70
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
71
|
+
attribute :srgb, srgb
|
|
72
|
+
attribute :sys, sys
|
|
73
|
+
|
|
74
|
+
xml do
|
|
75
|
+
namespace ns
|
|
76
|
+
element "color"
|
|
77
|
+
map_element "srgbClr", to: :srgb
|
|
78
|
+
map_element "sysClr", to: :sys
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
stub_const("ClrScheme::Color", klass)
|
|
82
|
+
klass
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
let(:scheme_class) do
|
|
86
|
+
ns = theme_ns
|
|
87
|
+
color = color_class
|
|
88
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
89
|
+
attribute :name, :string
|
|
90
|
+
attribute :colors, color, collection: true
|
|
91
|
+
|
|
92
|
+
xml do
|
|
93
|
+
namespace ns
|
|
94
|
+
element "clrScheme"
|
|
95
|
+
map_attribute "name", to: :name
|
|
96
|
+
map_element "color", to: :colors
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
stub_const("ClrScheme::Scheme", klass)
|
|
100
|
+
klass
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
let(:source) do
|
|
104
|
+
colors = %w[dk1 lt1 dk2 lt2 accent1 accent2 accent3 accent4 accent5
|
|
105
|
+
accent6 hlink folHlink].each_with_index.map do |_name, i|
|
|
106
|
+
if i.even?
|
|
107
|
+
%(<a:color><a:srgbClr val="C#{i}"/></a:color>)
|
|
108
|
+
else
|
|
109
|
+
%(<a:color><a:sysClr val="windowText" lastClr="00000#{i}"/></a:color>)
|
|
110
|
+
end
|
|
111
|
+
end.join
|
|
112
|
+
|
|
113
|
+
<<~XML
|
|
114
|
+
<a:clrScheme xmlns:a="http://example.com/theme" name="Office">
|
|
115
|
+
#{colors}
|
|
116
|
+
</a:clrScheme>
|
|
117
|
+
XML
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
let(:register) { Lutaml::Model::Config.default_register }
|
|
121
|
+
|
|
122
|
+
around do |example|
|
|
123
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "emits parsed unordered schemes with deferred grandchildren" do
|
|
127
|
+
instance = scheme_class.from_xml(source)
|
|
128
|
+
expect(Lutaml::Xml::Leptris::NativeEmission.compatible?(
|
|
129
|
+
Lutaml::Xml::Leptris::PlanCompiler.compile(scheme_class,
|
|
130
|
+
register),
|
|
131
|
+
instance,
|
|
132
|
+
register,
|
|
133
|
+
)).to be(true)
|
|
134
|
+
xml = instance.to_xml
|
|
135
|
+
expect(xml).to include('val="C0"')
|
|
136
|
+
expect(xml).to include('val="windowText"')
|
|
137
|
+
expect(xml.scan("<a:color>").size).to eq(12)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "round-trips every color entry through the emission" do
|
|
141
|
+
instance = scheme_class.from_xml(source)
|
|
142
|
+
restored = scheme_class.from_xml(instance.to_xml)
|
|
143
|
+
expect(restored.name).to eq("Office")
|
|
144
|
+
expect(restored.colors.size).to eq(12)
|
|
145
|
+
expect(restored.colors[0].srgb.val).to eq("C0")
|
|
146
|
+
expect(restored.colors[0].srgb.sys.nil?).to be(true)
|
|
147
|
+
expect(restored.colors[1].sys.val).to eq("windowText")
|
|
148
|
+
expect(restored.colors[1].sys.last_clr).to eq("000001")
|
|
149
|
+
expect(restored.colors[10].srgb.val).to eq("C10")
|
|
150
|
+
expect(restored.colors[11].sys.last_clr).to eq("0000011")
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# tree
|
|
8
|
-
#
|
|
3
|
+
# The engine's ops lane spells prefix:local for every EXACT row and
|
|
4
|
+
# cannot express the default-xmlns form — so namespaced trees ride
|
|
5
|
+
# the lane only under a prefixed-preserved root (Priority 1 format
|
|
6
|
+
# preservation; the DOM lane inherits the root prefix down the
|
|
7
|
+
# tree). Constructed and default-parsed roots pin the default-xmlns
|
|
8
|
+
# form and MUST take the DOM lane (uniword bold/custprops format
|
|
9
|
+
# regressions when the lane admitted them).
|
|
9
10
|
|
|
10
11
|
require "lutaml/model"
|
|
11
12
|
require "lutaml/xml/leptris"
|
|
@@ -40,17 +41,29 @@ RSpec.describe Lutaml::Xml::Leptris::NativeEmission do
|
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
|
|
43
|
-
let(:instance) { model_class.new(id: "7", value: "hello") }
|
|
44
44
|
let(:register) { Lutaml::Model::Config.default_register }
|
|
45
45
|
let(:plan) { Lutaml::Xml::Leptris::PlanCompiler.compile(model_class, register) }
|
|
46
46
|
|
|
47
|
-
it "
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
it "rejects a constructed namespaced tree in the compatibility gate" do
|
|
48
|
+
expect(described_class.compatible?(plan)).to be(false)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "serializes constructed namespaced models in the default-xmlns format" do
|
|
52
|
+
xml = model_class.new(id: "7", value: "hello").to_xml
|
|
53
|
+
expect(xml).to include('<element xmlns="http://example.com/ns"')
|
|
54
|
+
expect(xml).not_to include("ex:")
|
|
51
55
|
end
|
|
52
56
|
|
|
53
|
-
it "
|
|
54
|
-
|
|
57
|
+
it "admits a namespaced tree under a prefixed-preserved root" do
|
|
58
|
+
source = '<ex:element xmlns:ex="http://example.com/ns">' \
|
|
59
|
+
"<ex:id>7</ex:id><ex:value>hello</ex:value></ex:element>"
|
|
60
|
+
instance = model_class.from_xml(source)
|
|
61
|
+
expect(instance.xml_namespace_prefix).to eq("ex")
|
|
62
|
+
expect(described_class.compatible?(plan, instance, register)).to be(true)
|
|
63
|
+
native = described_class.emit(instance, plan, register)
|
|
64
|
+
expect(native).to include("ex:element")
|
|
65
|
+
reparsed = model_class.from_xml(native)
|
|
66
|
+
expect(reparsed.id).to eq("7")
|
|
67
|
+
expect(reparsed.value).to eq("hello")
|
|
55
68
|
end
|
|
56
69
|
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# lutaml-model#1131: parsed schemas retain the document's xmlns
|
|
4
|
+
# declarations so qualified QNames resolve exactly. particlesQ032's
|
|
5
|
+
# chameleon-import class imports three documents each declaring a
|
|
6
|
+
# global `e2`; the content model references foo:e2 / x:e2 / bar:e2 —
|
|
7
|
+
# the prefixes ARE the semantics, and the declaration plan's
|
|
8
|
+
# URI-keyed registry cannot represent several prefixes bound to one
|
|
9
|
+
# URI.
|
|
10
|
+
|
|
11
|
+
require "lutaml/model"
|
|
12
|
+
require "lutaml/xml/schema/xsd"
|
|
13
|
+
|
|
14
|
+
RSpec.describe "xmlns declarations retained on parsed Schema" do
|
|
15
|
+
let(:xsd) do
|
|
16
|
+
<<~XML
|
|
17
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
18
|
+
xmlns:foo="http://example.com/foo"
|
|
19
|
+
xmlns:x="http://example.com/foo"
|
|
20
|
+
xmlns:bar="http://example.com/bar"
|
|
21
|
+
targetNamespace="http://example.com/main"
|
|
22
|
+
elementFormDefault="qualified">
|
|
23
|
+
<xs:import namespace="http://example.com/foo"/>
|
|
24
|
+
<xs:import namespace="http://example.com/bar"/>
|
|
25
|
+
<xs:element name="root">
|
|
26
|
+
<xs:complexType>
|
|
27
|
+
<xs:sequence>
|
|
28
|
+
<xs:element ref="foo:e2"/>
|
|
29
|
+
<xs:element ref="x:e2"/>
|
|
30
|
+
<xs:element ref="bar:e2"/>
|
|
31
|
+
</xs:sequence>
|
|
32
|
+
</xs:complexType>
|
|
33
|
+
</xs:element>
|
|
34
|
+
</xs:schema>
|
|
35
|
+
XML
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
let(:schema) do
|
|
39
|
+
Lutaml::Xml::Schema::Xsd.parse(xsd, location: "particles_q032.xsd")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "retains every declared prefix with its URI" do
|
|
43
|
+
declarations = schema.xmlns_declarations
|
|
44
|
+
expect(declarations["xs"]).to eq("http://www.w3.org/2001/XMLSchema")
|
|
45
|
+
expect(declarations["foo"]).to eq("http://example.com/foo")
|
|
46
|
+
expect(declarations["x"]).to eq("http://example.com/foo")
|
|
47
|
+
expect(declarations["bar"]).to eq("http://example.com/bar")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "keeps prefixes the declaration plan's URI-keyed registry collapses" do
|
|
51
|
+
# foo: and x: bind the SAME URI — an exact prefix→URI map must
|
|
52
|
+
# carry both spellings; the plan registry keeps only the last.
|
|
53
|
+
expect(schema.xmlns_declarations.fetch("foo"))
|
|
54
|
+
.to eq(schema.xmlns_declarations.fetch("x"))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "resolves the particlesQ032 reference prefixes exactly" do
|
|
58
|
+
declarations = schema.xmlns_declarations
|
|
59
|
+
%w[foo x bar].each do |prefix|
|
|
60
|
+
expect(declarations).to have_key(prefix)
|
|
61
|
+
expect(declarations[prefix]).to start_with("http://example.com/")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "captures a plain XML document's declarations with the default under nil" do
|
|
66
|
+
ns = Class.new(Lutaml::Xml::Namespace) do
|
|
67
|
+
uri "http://example.com/doc"
|
|
68
|
+
prefix_default "d"
|
|
69
|
+
end
|
|
70
|
+
model = Class.new(Lutaml::Model::Serializable) do
|
|
71
|
+
attribute :child, :string
|
|
72
|
+
|
|
73
|
+
xml do
|
|
74
|
+
namespace ns
|
|
75
|
+
element "doc"
|
|
76
|
+
map_element "child", to: :child
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
instance = model.from_xml(
|
|
81
|
+
'<doc xmlns="http://example.com/doc" ' \
|
|
82
|
+
'xmlns:p="http://example.com/p"><child>x</child></doc>',
|
|
83
|
+
)
|
|
84
|
+
expect(instance.xmlns_declarations[nil]).to eq("http://example.com/doc")
|
|
85
|
+
expect(instance.xmlns_declarations["p"]).to eq("http://example.com/p")
|
|
86
|
+
end
|
|
87
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.167
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -2018,6 +2018,7 @@ files:
|
|
|
2018
2018
|
- spec/lutaml/xml/general_namespace_spec.rb
|
|
2019
2019
|
- spec/lutaml/xml/html_entities_spec.rb
|
|
2020
2020
|
- spec/lutaml/xml/indent_spec.rb
|
|
2021
|
+
- spec/lutaml/xml/leptris/native_emission_nested_sharing_spec.rb
|
|
2021
2022
|
- spec/lutaml/xml/leptris/native_emission_ns_parity_spec.rb
|
|
2022
2023
|
- spec/lutaml/xml/leptris/native_emission_ordered_spec.rb
|
|
2023
2024
|
- spec/lutaml/xml/leptris/native_emission_raw_gate_spec.rb
|
|
@@ -2101,6 +2102,7 @@ files:
|
|
|
2101
2102
|
- spec/lutaml/xml/schema/xsd/schema_helper_methods_spec.rb
|
|
2102
2103
|
- spec/lutaml/xml/schema/xsd/schema_mapping_spec.rb
|
|
2103
2104
|
- spec/lutaml/xml/schema/xsd/schema_validator_spec.rb
|
|
2105
|
+
- spec/lutaml/xml/schema/xsd/schema_xmlns_declarations_spec.rb
|
|
2104
2106
|
- spec/lutaml/xml/schema/xsd/spec_helper.rb
|
|
2105
2107
|
- spec/lutaml/xml/schema/xsd/unresolvable_schema_location_spec.rb
|
|
2106
2108
|
- spec/lutaml/xml/schema/xsd/validation_error_spec.rb
|