lutaml-model 0.8.206 → 0.8.207

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: eab7d971a6cba2786d724c87b9cf76e6bd5dcfc8b18291748ea9c14d1f0d6e90
4
- data.tar.gz: 32ca845f618f08d9ae94278188ccad27fa4aec91fc5c00abe48876b552589425
3
+ metadata.gz: d100be5e75a2c176f69d9367bc66bf67ea65655ca6c181047b9aa97b1b985ac2
4
+ data.tar.gz: '09942944fdc1ef7e16a229e56d88e07c4304307748dd6fe0cafc846f688299e2'
5
5
  SHA512:
6
- metadata.gz: 928e1d25192b585379158191088e6e198694998141a614b6852e741449e990f95512158852b9ca28b1431a5a7bbcc5e7fd4db95cff873bb0f511a44681125132
7
- data.tar.gz: a451b8ae1a886fe2a3f859de5c13d92414613e58e161acad16a8658e165901eee8fd72e554c60739085189eb3ae4818b02faa01f9e1066f43366b18ff14b9410
6
+ metadata.gz: 8474edf89b9345787bc78e804d8b1495cdb144a3d0e8c4821a11e1943634dc8b7d2c32ba5dc1d17e25d40290a2ed83691a668f472c34d537195ba9367ddc4b72
7
+ data.tar.gz: fbedc7fb3cee383cd5351cbd35f4205af91f052331be46eceba41839bc1dd14451176a73ba30b20c583592f5e4b039fa40f7da802f9856b3d279243a930b99a3
@@ -92,6 +92,22 @@ the mapped one — and one stays interpretive for an engine reason: an
92
92
  `xsi:nil` mark on a nested element (below the root's own children),
93
93
  which the engine walk does not surface.
94
94
 
95
+ Round trips keep what the parsed root declared. Every namespace the
96
+ source declared on the root is declared again — an extra vocabulary the
97
+ document carried, the prefix a captured raw fragment spells, or a
98
+ second prefix a default-namespace root bound its own namespace to —
99
+ exactly as the standard pipeline keeps them. A `render_nil` element
100
+ spells `xsi:nil`, and a constructed document declares the `xsi` prefix
101
+ for it on the root (a parsed one already carries the declaration).
102
+
103
+ Parsing strictness is a property of the lane unless you ask for
104
+ otherwise: the leptris plan lane parses strictly (malformed input
105
+ raises `InvalidFormatError`), while the standard pipeline recovers
106
+ whatever its engine recovers — Nokogiri recovers most malformed input
107
+ into a best-effort tree. `from_xml(xml, strict: true)` asks for the
108
+ raising contract on every lane; the `lutaml-model compare` command
109
+ always parses strictly.
110
+
95
111
  Version floor note: leptris 1.9.320+ retains child-row namespace
96
112
  URIs engine-side and matches plain attribute rows against
97
113
  namespace-qualified wire spellings. On older engines, models whose
@@ -233,6 +233,10 @@ Error parsing file data.xml: Invalid XML syntax
233
233
  ----
234
234
  *Solution:* Verify file format and syntax. The CLI will attempt to parse files according to their extension.
235
235
 
236
+ XML files are parsed strictly: a malformed document is reported as above
237
+ rather than compared as a recovered tree, whatever the engine would have
238
+ recovered from it.
239
+
236
240
  == Supported File Formats
237
241
 
238
242
  The compare command automatically detects file format based on extension:
@@ -70,7 +70,13 @@ module Lutaml
70
70
  format = path.split(".").last.downcase
71
71
  format = "yaml" if format == "yml"
72
72
 
73
- model.public_send("from_#{format}", content)
73
+ if format == "xml"
74
+ # A malformed document is reported, never compared as a
75
+ # recovered tree — whatever the engine would recover.
76
+ model.from_xml(content, strict: true)
77
+ else
78
+ model.public_send("from_#{format}", content)
79
+ end
74
80
  rescue StandardError => e
75
81
  raise StandardError, "Error parsing file #{path}: #{e.message}"
76
82
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.206"
5
+ VERSION = "0.8.207"
6
6
  end
7
7
  end
@@ -294,6 +294,7 @@ module Lutaml
294
294
  # Check if element was created from nil value with render_nil option
295
295
  if element.is_a?(Lutaml::Xml::DataModel::XmlElement) && element.xsi_nil
296
296
  attributes["xsi:nil"] = true
297
+ declare_xsi_prefix(xml)
297
298
  end
298
299
 
299
300
  # Create element
@@ -472,6 +473,21 @@ module Lutaml
472
473
 
473
474
  private
474
475
 
476
+ # xsi:nil spells the xsi prefix: the document root declares it,
477
+ # as it does for xsi:schemaLocation (a parsed source's own
478
+ # declaration is kept by the stored plan, so this adds nothing
479
+ # on a round trip).
480
+ def declare_xsi_prefix(xml)
481
+ root = xml.doc.root
482
+ return unless root
483
+ return if root.in_scope_namespaces.any? do |ns|
484
+ ns.prefix == W3c::XsiNamespace.prefix_default
485
+ end
486
+
487
+ root.add_namespace(W3c::XsiNamespace.prefix_default,
488
+ W3c::XsiNamespace.uri)
489
+ end
490
+
475
491
  def build_type_only_element(xml, element, xml_mapping, plan, options,
476
492
  mapper_class)
477
493
  if options[:tag_name]
@@ -17,7 +17,8 @@ module Lutaml
17
17
  parse_encoding = encoding(xml, options)
18
18
  raw_xml = xml
19
19
  xml = normalize_xml_for_parse(xml)
20
- parsed = parse_with_moxml(xml, parse_encoding)
20
+ parsed = parse_with_moxml(xml, parse_encoding,
21
+ strict: options[:strict])
21
22
  root_element = parsed.root
22
23
 
23
24
  raise_empty_document_error(parsed.parse_errors) if root_element.nil?
@@ -46,15 +47,19 @@ module Lutaml
46
47
  replace: "?")
47
48
  end
48
49
 
49
- def parse_with_moxml(xml, parse_encoding)
50
+ # strict: the engine raises on malformed input instead of
51
+ # recovering a best-effort tree (what a `from_xml(strict: true)`
52
+ # caller asks for; the leptris plan lane parses strictly anyway).
53
+ def parse_with_moxml(xml, parse_encoding, strict: nil)
50
54
  parse_error_class = parse_error_class_or_nil
55
+ moxml_options = { encoding: parse_encoding }
56
+ moxml_options[:strict] = true if strict
51
57
  unless parse_error_class
52
- return moxml_adapter_class.parse(xml,
53
- encoding: parse_encoding)
58
+ return moxml_adapter_class.parse(xml, **moxml_options)
54
59
  end
55
60
 
56
61
  begin
57
- moxml_adapter_class.parse(xml, encoding: parse_encoding)
62
+ moxml_adapter_class.parse(xml, **moxml_options)
58
63
  rescue parse_error_class => e
59
64
  raise Lutaml::Model::InvalidFormatError.new(:xml, e.message)
60
65
  end
@@ -264,6 +264,7 @@ module Lutaml
264
264
 
265
265
  if xml_element.is_a?(Lutaml::Xml::DataModel::XmlElement) && xml_element.xsi_nil
266
266
  attributes["xsi:nil"] = "true"
267
+ declare_xsi_prefix(xml)
267
268
  end
268
269
 
269
270
  attributes.merge!(element_node.schema_location_attr) if element_node.schema_location_attr
@@ -60,6 +60,11 @@ module Lutaml
60
60
  # A nil instance runs the static checks only.
61
61
  def compatible?(plan, instance = nil, register = nil)
62
62
  return false if plan.nil?
63
+ # Source declarations the ops layout cannot spell (an extra
64
+ # vocabulary the parsed root declared, a second prefix for a
65
+ # declared namespace): the DOM lane re-declares them.
66
+ return false if instance &&
67
+ PlanSerializer.stored_declarations_uncovered?(plan, instance)
63
68
  # A tracked element_order on an unordered plan (#977) is the
64
69
  # DOM lane's ordered walk; the flat ops layout emits mapping
65
70
  # order.
@@ -666,9 +666,12 @@ module Lutaml
666
666
  # reader's shape: the text runs when the element has
667
667
  # non-text children (validate flags a singular target
668
668
  # holding them), the joined text otherwise.
669
+ # Several runs mean non-text nodes between them (text
670
+ # nodes only split at a child boundary).
669
671
  instance.public_send(:"#{attr.name}=",
670
672
  content_text(node, runs,
671
- element_children))
673
+ element_children ||
674
+ runs.size > 1))
672
675
  when :raw
673
676
  raws = raw_strings(value, wire_name)
674
677
  next if raws.empty?
@@ -848,11 +851,11 @@ module Lutaml
848
851
  # The interpretive XmlElement#text shape for a singular
849
852
  # content attribute: the text runs when the source element has
850
853
  # non-text children (mixed content), the joined text otherwise.
851
- # Mapped element children show in the walk's own capture; an
852
- # unmapped one only on the source node, consulted when the
853
- # hydration already holds it (the buckets chain is not kept
854
- # for this — 85 singular content attributes ride every NISO
855
- # JATS paragraph).
854
+ # Mapped element children and child-split runs show in the
855
+ # walk's own capture; a single run beside an unmapped element
856
+ # only on the source node, consulted when the hydration already
857
+ # holds it (the buckets chain is not kept for this — 85
858
+ # singular content attributes ride every NISO JATS paragraph).
856
859
  def content_text(node, runs, element_children)
857
860
  return runs if element_children
858
861
  return runs.join unless node
@@ -119,9 +119,7 @@ module Lutaml
119
119
  if instance.is_a?(::Lutaml::Model::Serialize) &&
120
120
  instance.raw_schema_location &&
121
121
  !instance.raw_schema_location.empty?
122
- root.set_attribute(
123
- "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
124
- )
122
+ ns_ctx.declare_xsi_on(root)
125
123
  root.set_attribute("xsi:schemaLocation",
126
124
  instance.raw_schema_location)
127
125
  end
@@ -161,6 +159,7 @@ module Lutaml
161
159
  @model_prefix = nil
162
160
  @forms = {}
163
161
  @hoisted = {}
162
+ @extra_declarations = []
164
163
  @declared = {}
165
164
  @unspellable = false
166
165
  mapping = plan[:mapping]
@@ -219,25 +218,33 @@ module Lutaml
219
218
  @hoisted[model_uri] = ns_prefix
220
219
  @forms[model_uri] = { prefix: ns_prefix, uri: model_uri }
221
220
  end
222
- # Source declaration preservation (the interpretive
223
- # writer's stored-plan merge): prefixes the parsed source
224
- # declared are kept for URIs the document emits. The
225
- # planner's class-analysis path has no stored-plan
226
- # access, so the merge reads the instance's recorded plan
227
- # directly.
221
+ # Source declaration preservation (the interpretive writer's
222
+ # stored-plan behavior): every namespace the parsed source
223
+ # declared on the root is declared again. The ones the
224
+ # planner recomputed keep the planner's spelling (format
225
+ # preservation); the rest ride along verbatim — an extra
226
+ # vocabulary the root declared, or the prefix a captured
227
+ # raw fragment spells. A default-namespace source that also
228
+ # bound a declared URI to a prefix keeps that second
229
+ # declaration (the doubly-defined root); a prefixed source
230
+ # does not (the interpretive merge skips it).
228
231
  stored = if instance.is_a?(::Lutaml::Model::Serialize)
229
232
  instance.import_declaration_plan
230
233
  end
231
234
  if stored.is_a?(Lutaml::Xml::DeclarationPlan) &&
232
235
  stored.root_node.is_a?(
233
236
  Lutaml::Xml::DeclarationPlan::ElementNode,
234
- ) && (ns_prefix.nil? || ns_prefix.empty?)
235
- original_uris = stored.original_namespace_uris || {}
237
+ )
238
+ prefixed_source = ns_prefix && !ns_prefix.empty?
236
239
  stored.root_node.hoisted_declarations.each do |prefix, uri|
237
- effective_uri = original_uris[uri] || uri
238
- already = @hoisted.value?(effective_uri) ||
239
- @hoisted.value?(uri)
240
- @hoisted[prefix] = uri if already && !@hoisted.key?(prefix)
240
+ if @hoisted.key?(uri)
241
+ next if prefixed_source || prefix.nil? || @hoisted[uri] == prefix
242
+
243
+ @extra_declarations << [prefix, uri]
244
+ else
245
+ @hoisted[uri] = prefix
246
+ @forms[uri] = { prefix: prefix, uri: uri }
247
+ end
241
248
  end
242
249
  end
243
250
  collect(plan[:tree])
@@ -265,6 +272,19 @@ module Lutaml
265
272
  @unspellable
266
273
  end
267
274
 
275
+ # The xsi prefix for a raw xsi:schemaLocation — declared once
276
+ # with the plan's other declarations (a parsed source's own
277
+ # declaration is kept above).
278
+ def declare_xsi_on(root)
279
+ uri = Lutaml::Xml::W3c::XsiNamespace.uri
280
+ return if @declared[uri]
281
+
282
+ root.add_namespace_definition(
283
+ Lutaml::Xml::W3c::XsiNamespace.prefix_default, uri
284
+ )
285
+ @declared[uri] = true
286
+ end
287
+
268
288
  # Whether the root declares a default namespace — every
269
289
  # element then has one in scope until a :blank child opts
270
290
  # out with xmlns="".
@@ -335,6 +355,13 @@ module Lutaml
335
355
  @declared[uri] = true
336
356
  root.add_namespace_definition(prefix, uri)
337
357
  end
358
+ @extra_declarations.each do |prefix, uri|
359
+ next if uri.nil? || uri == XML_NAMESPACE_URI ||
360
+ @declared[[prefix, uri]]
361
+
362
+ @declared[[prefix, uri]] = true
363
+ root.add_namespace_definition(prefix, uri)
364
+ end
338
365
  end
339
366
  end
340
367
 
@@ -765,6 +792,44 @@ module Lutaml
765
792
  RECONCILER.order_entry?(object)
766
793
  end
767
794
 
795
+ # Whether the parsed source declared anything the plan's own
796
+ # namespaces do not cover — an extra vocabulary on the root, or
797
+ # a second prefix for a declared namespace. The ops layout
798
+ # cannot spell those; the DOM lane re-declares them (the
799
+ # interpretive writer's stored-plan behavior).
800
+ def stored_declarations_uncovered?(plan, instance)
801
+ return false unless instance.is_a?(::Lutaml::Model::Serialize)
802
+
803
+ stored = instance.import_declaration_plan
804
+ return false unless stored.is_a?(Lutaml::Xml::DeclarationPlan) &&
805
+ stored.root_node.is_a?(Lutaml::Xml::DeclarationPlan::ElementNode)
806
+
807
+ declared = stored.root_node.hoisted_declarations
808
+ return false if declared.empty?
809
+
810
+ uris = declared_uris(plan)
811
+ declared.values.uniq.size != declared.size ||
812
+ declared.values.any? { |uri| !uris.include?(uri) }
813
+ end
814
+
815
+ # The namespace URIs the plan's emission declares on its root.
816
+ def declared_uris(plan)
817
+ plan[:declared_uris] ||= tree_uris(plan[:tree], {}).freeze
818
+ end
819
+
820
+ def tree_uris(tree, uris)
821
+ collect_uri = lambda do |ns|
822
+ uris[ns[:exact]] = true if ns.is_a?(::Hash) && ns[:exact]
823
+ end
824
+ collect_uri.call(tree[:ns])
825
+ (tree[:attributes] || []).each { |a| collect_uri.call(a[:ns]) }
826
+ (tree[:children] || []).each do |row|
827
+ collect_uri.call(row[:ns])
828
+ tree_uris(row[:plan], uris) if row[:plan]
829
+ end
830
+ uris
831
+ end
832
+
768
833
  # Whether an instance serializes through the ordered walk: an
769
834
  # ordered/mixed plan, or an instance carrying a programmatically
770
835
  # tracked element_order (the order-tracker pattern, lutaml-model
@@ -1048,7 +1113,10 @@ module Lutaml
1048
1113
  xsi_nil: false)
1049
1114
  child = element.create_child(name)
1050
1115
  attrs&.each { |k, v| child[k.to_s] = v.to_s }
1051
- child.set_attribute("xsi:nil", "true") if xsi_nil
1116
+ if xsi_nil
1117
+ child.set_attribute("xsi:nil", "true")
1118
+ declare_xsi_prefix(doc)
1119
+ end
1052
1120
  # An uninitialized value rendered under its value_map is an
1053
1121
  # empty element (the interpretive serialize_value yields no
1054
1122
  # text for it).
@@ -1058,6 +1126,21 @@ module Lutaml
1058
1126
  child
1059
1127
  end
1060
1128
 
1129
+ # xsi:nil spells the xsi prefix: the document root declares it,
1130
+ # as a parsed source's own declaration is kept (the stored
1131
+ # plan re-emits it) — a constructed tree carries none.
1132
+ def declare_xsi_prefix(doc)
1133
+ root = doc.root
1134
+ return unless root
1135
+
1136
+ prefix = Lutaml::Xml::W3c::XsiNamespace.prefix_default
1137
+ return if root["xmlns:#{prefix}"] ||
1138
+ root.namespace_definitions.any? { |ns| ns.prefix == prefix }
1139
+
1140
+ root.add_namespace_definition(prefix,
1141
+ Lutaml::Xml::W3c::XsiNamespace.uri)
1142
+ end
1143
+
1061
1144
  # A collection row's emission (the interpretive
1062
1145
  # apply_collection_element contract): one leaf per item — a
1063
1146
  # nil item goes unrendered when the value_map omits nil — and
@@ -1112,7 +1195,8 @@ module Lutaml
1112
1195
  # Shared with NativeEmission's gate: the order-entry predicate,
1113
1196
  # the render-policy placeholder and the coverage pre-check
1114
1197
  # decide what the ops lane cannot serve.
1115
- public :order_entry?, :ordered_walk?, :placeholder_for, :order_uncovered?
1198
+ public :order_entry?, :ordered_walk?, :placeholder_for, :order_uncovered?,
1199
+ :stored_declarations_uncovered?
1116
1200
 
1117
1201
  # Whether a row's value reaches the output at all — the
1118
1202
  # interpretive should_skip_value? contract (RenderPolicy): an
@@ -146,8 +146,15 @@ module Lutaml
146
146
  end
147
147
  end
148
148
  root_and_parent_assignment(instance, options)
149
- apply_xml_mapping(ParseSession.new(data, instance, options,
150
- child_register))
149
+ parsed = apply_xml_mapping(ParseSession.new(data, instance, options,
150
+ child_register))
151
+ # A parsed instance is pristine on every lane: the parse's own
152
+ # writer calls are not a mutation of the parsed state (the plan
153
+ # lanes' hydrator resets the same flag after construction).
154
+ if instance_is_serialize
155
+ instance.clear_mutated_after_parse!
156
+ end
157
+ parsed
151
158
  end
152
159
 
153
160
  # Build a DeclarationPlan from the parsed element tree's namespace declarations.
data/lutaml-model.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "bigdecimal"
36
36
  spec.add_dependency "canon"
37
37
  spec.add_dependency "concurrent-ruby"
38
- spec.add_dependency "liquid", ">= 4.0", "< 6.0"
38
+ spec.add_dependency "liquid", "~> 5.14"
39
39
  # 0.5.84 always passes XML_PARSE_HUGE to libxml2: very large documents
40
40
  # parse completely instead of being silently truncated at the 10 MB
41
41
  # input-buffer cap (lutaml-model#871).
@@ -1 +1 @@
1
- {"capabilities":["json","xml"],"corpora":[{"generation":"core-v2","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:14c85f76a3cf2ebb18aa3c97186840897bf2147c886818a5c73670d3a6db170a"}],"files":[{"path":"index.json","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"},{"path":"schema.json","sha256":"sha256:ce5cc1c61e4a97bc71b2683b71e56c5488dbd3f41fdfa2802c01c4c2cd34fa1e"},{"path":"schema.yaml","sha256":"sha256:5c6f2cf9ddb907bd2aaff813711a6ed0d35e0ff1563d5b4f893301f803dac8e0"}],"generator_version":"ruby-core-oracle-v2","lml_checksum":"sha256:a7fac433ca7be94a6a66f6b8d0dab8134747860cf8076dffc4aaa92a24d1cb34","manifest":1,"schema_version":2,"target":"ruby"}
1
+ {"capabilities":["json","xml"],"corpora":[{"generation":"core-v2","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:480e5a78e34f290b28420d56b1f4aad0162a16c87067c21597e99e9b1dbca39e"}],"files":[{"path":"index.json","sha256":"sha256:fd1de9747a78a71d737a4076ebfb0cf4a561d96dba9156a43afb5a337ebad0d2"},{"path":"schema.json","sha256":"sha256:ce5cc1c61e4a97bc71b2683b71e56c5488dbd3f41fdfa2802c01c4c2cd34fa1e"},{"path":"schema.yaml","sha256":"sha256:5c6f2cf9ddb907bd2aaff813711a6ed0d35e0ff1563d5b4f893301f803dac8e0"}],"generator_version":"ruby-core-oracle-v2","lml_checksum":"sha256:a7fac433ca7be94a6a66f6b8d0dab8134747860cf8076dffc4aaa92a24d1cb34","manifest":1,"schema_version":2,"target":"ruby"}
@@ -1 +1 @@
1
- {"capabilities":["json","xml"],"corpora":[{"generation":"preservation-v1","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:14c85f76a3cf2ebb18aa3c97186840897bf2147c886818a5c73670d3a6db170a"}],"files":[{"path":"index.json","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"},{"path":"schema.json","sha256":"sha256:66b86b75d36568c1c353a2d5cf32d0e6562e21e7dfea0004a757d0f774761264"},{"path":"schema.yaml","sha256":"sha256:cf40d46e901e4a8e7bb4b7f7ad4365ffec687bef81832663dc136626b3963c3d"}],"generator_version":"ruby-preservation-oracle-v1","lml_checksum":"sha256:81eaac6230a81d4285fb4ea743f202234ef3f3c48482ca60ce9e9b642a5622e5","manifest":1,"schema_version":2,"target":"ruby"}
1
+ {"capabilities":["json","xml"],"corpora":[{"generation":"preservation-v1","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"}],"dependencies":[{"name":"lutaml-model","revision":"8a8ef040963b7965388b01b58af33af2b0995f91","sha256":"sha256:480e5a78e34f290b28420d56b1f4aad0162a16c87067c21597e99e9b1dbca39e"}],"files":[{"path":"index.json","sha256":"sha256:76d942557692ee653136f10fcf98e5b3beef43d9ed9a9082eb6d17002b64ddd9"},{"path":"schema.json","sha256":"sha256:66b86b75d36568c1c353a2d5cf32d0e6562e21e7dfea0004a757d0f774761264"},{"path":"schema.yaml","sha256":"sha256:cf40d46e901e4a8e7bb4b7f7ad4365ffec687bef81832663dc136626b3963c3d"}],"generator_version":"ruby-preservation-oracle-v1","lml_checksum":"sha256:81eaac6230a81d4285fb4ea743f202234ef3f3c48482ca60ce9e9b642a5622e5","manifest":1,"schema_version":2,"target":"ruby"}
@@ -334,24 +334,14 @@ RSpec.describe Lutaml::Model::Cli do
334
334
 
335
335
  after { FileUtils.rm_rf(temp_dir) }
336
336
 
337
- it "handles malformed XML according to the engine's parse contract" do
337
+ it "reports malformed XML instead of comparing a recovered tree" do
338
338
  cli.options = options
339
339
 
340
- # The leptris plan lane parses strictly (malformed XML raises on
341
- # every lane, 17a4658d): the CLI reports the parse failure. A
342
- # recovering engine (Nokogiri) hands it a best-effort tree and
343
- # the comparison runs on that.
344
- if Lutaml::Xml.moxml_engine == :leptris
345
- expect do
346
- cli.compare(malformed_xml, files[:target_xml_path])
347
- end.to raise_error(StandardError, /Error parsing file .*malformed\.xml/)
348
- else
349
- expect do
350
- cli.compare(malformed_xml, files[:target_xml_path])
351
- end.to output(
352
- a_string_including("Differences between", "Similarity score:"),
353
- ).to_stdout
354
- end
340
+ # The comparison parses strictly: a malformed document is an
341
+ # error on every engine, never a best-effort tree to diff.
342
+ expect do
343
+ cli.compare(malformed_xml, files[:target_xml_path])
344
+ end.to raise_error(StandardError, /Error parsing file .*malformed\.xml/)
355
345
  end
356
346
 
357
347
  it "raises error when parsing malformed YAML" do
@@ -84,6 +84,10 @@ RSpec.describe "LML review round-4 probe fixes (encoding, float enums, bundle in
84
84
  end
85
85
 
86
86
  describe "Bundle construction" do
87
+ # The sets are large enough that a build takes tens of milliseconds: at
88
+ # 1000/4000 models the builds took 5-25 ms, and a shared runner could
89
+ # report a 14x ratio for the same linear code (lutaml-model#1328). The
90
+ # best of three drops the stragglers.
87
91
  it "scales linearly with the number of models" do
88
92
  build = lambda do |count|
89
93
  models = (0...count).to_h { |i| ["R5M#{i}@default", minimal_model("R5M#{i}")] }
@@ -91,9 +95,9 @@ RSpec.describe "LML review round-4 probe fixes (encoding, float enums, bundle in
91
95
  lml::Bundle.new(roots: [], models: models)
92
96
  Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
93
97
  end
94
- build.call(500)
95
- small = [build.call(1000), build.call(1000)].min
96
- large = [build.call(4000), build.call(4000)].min
98
+ build.call(2_000)
99
+ small = Array.new(3) { build.call(10_000) }.min
100
+ large = Array.new(3) { build.call(40_000) }.min
97
101
 
98
102
  expect(large / small).to be < 12
99
103
  end
@@ -132,8 +132,9 @@ RSpec.describe RenderNil do
132
132
  end
133
133
 
134
134
  it "serializes to XML with render_nil option" do
135
+ # xsi:nil spells the xsi prefix: the root declares it.
135
136
  expected_xml = <<~XML
136
- <render_nil>
137
+ <render_nil xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
137
138
  <name xsi:nil="true"/>
138
139
  <glaze xsi:nil="true"/>
139
140
  <render_nil_nested/>
@@ -185,8 +185,9 @@ RSpec.describe "ValueMap" do
185
185
  end
186
186
 
187
187
  let(:expected_xml) do
188
+ # xsi:nil spells the xsi prefix: the root declares it.
188
189
  <<~XML.strip
189
- <WithValueMaps>
190
+ <WithValueMaps xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
190
191
  <omittedAsNil xsi:nil="true"/>
191
192
  <omittedAsEmpty/>
192
193
  <nilAsNil xsi:nil="true"/>
@@ -500,6 +500,81 @@ module ProductionLaneParitySpec
500
500
  end
501
501
  end
502
502
 
503
+ # A namespaced model with a raw capture: the parsed root's extra
504
+ # declarations must survive the round trip (the interpretive writer's
505
+ # stored-plan behavior).
506
+ RawDocNs = Class.new(Lutaml::Xml::W3c::XmlNamespace) do
507
+ uri "http://example.com/production-lane/raw-doc"
508
+ prefix_default "d"
509
+ end
510
+
511
+ class RawDoc < Lutaml::Model::Serializable
512
+ attribute :title, :string
513
+ attribute :svg_data, :string
514
+
515
+ xml do
516
+ element "doc"
517
+ namespace RawDocNs
518
+ map_element "title", to: :title
519
+ map_element "svg", to: :svg_data, raw: :element
520
+ end
521
+ end
522
+
523
+ DoubledNs = Class.new(Lutaml::Xml::W3c::XmlNamespace) do
524
+ uri "http://example.com/production-lane/doubled"
525
+ prefix_default "ex"
526
+ end
527
+
528
+ class Doubled < Lutaml::Model::Serializable
529
+ attribute :title, :string
530
+ attribute :code, :string
531
+
532
+ xml do
533
+ element "doubled"
534
+ namespace DoubledNs
535
+ map_element "title", to: :title
536
+ map_attribute "code", to: :code
537
+ end
538
+ end
539
+
540
+ class NilMarked < Lutaml::Model::Serializable
541
+ attribute :name, :string
542
+ attribute :note, :string
543
+
544
+ xml do
545
+ element "nil-marked"
546
+ map_element "name", to: :name
547
+ map_element "note", to: :note, render_nil: true
548
+ end
549
+ end
550
+
551
+ class StrictParsed < Lutaml::Model::Serializable
552
+ attribute :name, :string
553
+
554
+ xml do
555
+ element "strict"
556
+ map_content to: :name
557
+ end
558
+ end
559
+
560
+ class UnmappedChildContent < Lutaml::Model::Serializable
561
+ attribute :content, :string
562
+
563
+ xml do
564
+ element "unmapped-content"
565
+ map_content to: :content
566
+ end
567
+ end
568
+
569
+ class UnmappedHolder < Lutaml::Model::Serializable
570
+ attribute :inner, UnmappedChildContent
571
+
572
+ xml do
573
+ element "holder"
574
+ map_element "unmapped-content", to: :inner
575
+ end
576
+ end
577
+
503
578
  # An unordered mapping whose instances may carry a tracked
504
579
  # element_order (the order-tracker pattern, lutaml-model#977).
505
580
  class Tracked < Lutaml::Model::Serializable
@@ -870,6 +945,78 @@ RSpec.describe "production-lane parity" do
870
945
  expect(doc.to_xml).to be_xml_equivalent_to(xml)
871
946
  end
872
947
 
948
+ describe "source declarations" do
949
+ it "keeps the prefix a captured raw fragment spells" do
950
+ source = '<d:doc xmlns:d="http://example.com/production-lane/raw-doc" ' \
951
+ 'xmlns:s="http://www.w3.org/2000/svg">' \
952
+ "<d:title>T</d:title><s:svg><s:rect/></s:svg></d:doc>"
953
+ output = ProductionLaneParitySpec::RawDoc.from_xml(source).to_xml
954
+
955
+ expect(output).to include('xmlns:d="http://example.com/production-lane/raw-doc"',
956
+ 'xmlns:s="http://www.w3.org/2000/svg"', "<s:svg>")
957
+ end
958
+
959
+ it "keeps an extra vocabulary the parsed root declared" do
960
+ source = '<ex:doubled xmlns:ex="http://example.com/production-lane/doubled" ' \
961
+ 'xmlns:x="http://example.com/production-lane/extra" ex:code="c">' \
962
+ "<ex:title>T</ex:title></ex:doubled>"
963
+ output = ProductionLaneParitySpec::Doubled.from_xml(source).to_xml
964
+
965
+ expect(output).to include('xmlns:ex="http://example.com/production-lane/doubled"',
966
+ 'xmlns:x="http://example.com/production-lane/extra"')
967
+ end
968
+
969
+ it "keeps a second prefix a default-namespace root bound its namespace to" do
970
+ source = '<doubled xmlns="http://example.com/production-lane/doubled" ' \
971
+ 'xmlns:b="http://example.com/production-lane/doubled" code="c">' \
972
+ "<title>T</title></doubled>"
973
+ output = ProductionLaneParitySpec::Doubled.from_xml(source).to_xml
974
+
975
+ expect(output).to include('xmlns="http://example.com/production-lane/doubled"',
976
+ 'xmlns:b="http://example.com/production-lane/doubled"')
977
+ end
978
+ end
979
+
980
+ describe "parse and render contracts" do
981
+ it "declares the xsi prefix when a nil-marked element is rendered" do
982
+ output = ProductionLaneParitySpec::NilMarked.new(name: "a", note: nil).to_xml
983
+
984
+ expect(output).to include(
985
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', 'xsi:nil="true"'
986
+ )
987
+ expect { Lutaml::Xml.adapter.parse(output) }.not_to raise_error
988
+ end
989
+
990
+ it "raises on malformed input under strict: true" do
991
+ expect do
992
+ ProductionLaneParitySpec::StrictParsed.from_xml(
993
+ "<?xml version='1.0'?><strict>>malformed<<xml>", strict: true
994
+ )
995
+ end.to raise_error(Lutaml::Model::InvalidFormatError)
996
+ end
997
+
998
+ it "leaves a parsed instance pristine" do
999
+ parsed = ProductionLaneParitySpec::NilMarked.from_xml(
1000
+ "<nil-marked><name>a</name></nil-marked>",
1001
+ )
1002
+ expect(parsed.mutated_after_parse?).to be(false)
1003
+
1004
+ parsed.name = "b"
1005
+ expect(parsed.mutated_after_parse?).to be(true)
1006
+ end
1007
+
1008
+ it "binds the runs of a singular content element split by an unmapped child" do
1009
+ at_root = ProductionLaneParitySpec::UnmappedChildContent.from_xml(
1010
+ "<unmapped-content>a<unknown/></unmapped-content>",
1011
+ )
1012
+ nested = ProductionLaneParitySpec::UnmappedHolder.from_xml(
1013
+ "<holder><unmapped-content>one<unknown/>two</unmapped-content></holder>",
1014
+ )
1015
+ expect(at_root.content).to eq(["a"])
1016
+ expect(nested.inner.content).to eq(["one", "two"])
1017
+ end
1018
+ end
1019
+
873
1020
  describe "conversion caching" do
874
1021
  let(:store) { Lutaml::Store::BasicStore.new(adapter: { type: :memory }) }
875
1022
 
data/spec/spec_helper.rb CHANGED
@@ -39,12 +39,29 @@ RSpec.configure do |config|
39
39
  # machinery follows the CURRENT config by design (#1184), which
40
40
  # turned that leak into order-dependent schema-suite failures —
41
41
  # the restore pins every example back to the spec_helper default.
42
+ #
43
+ # "Previous" has three shapes and each needs its own restore: a type
44
+ # name, a pre-resolved adapter class (the resolver records it under
45
+ # its internal fixed-adapter marker, which the type setter refuses),
46
+ # or nothing — the production lane, which a leaked pin must be
47
+ # UNSET from rather than left in place. Skipping the nil case let the
48
+ # first spec that pinned :nokogiri hand every later spec that engine:
49
+ # the suite then passed on output the production leptris lane never
50
+ # produced (cdata rules serialized as escaped text).
42
51
  config.around do |example|
43
52
  previous = Lutaml::Model::Config.xml_adapter_type
53
+ fixed = previous == Lutaml::Model::FIXED_ADAPTER_TYPE
54
+ previous_adapter = Lutaml::Model::Config.xml_adapter if fixed
44
55
  begin
45
56
  example.run
46
57
  ensure
47
- Lutaml::Model::Config.xml_adapter_type = previous if previous
58
+ if fixed
59
+ Lutaml::Model::Config.xml_adapter = previous_adapter
60
+ elsif previous
61
+ Lutaml::Model::Config.xml_adapter_type = previous
62
+ else
63
+ Lutaml::Model::Config.unset_xml_adapter_type
64
+ end
48
65
  end
49
66
  end
50
67
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.206
4
+ version: 0.8.207
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-12-05 00:00:00.000000000 Z
11
+ date: 2026-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -70,22 +70,16 @@ dependencies:
70
70
  name: liquid
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '4.0'
76
- - - "<"
73
+ - - "~>"
77
74
  - !ruby/object:Gem::Version
78
- version: '6.0'
75
+ version: '5.14'
79
76
  type: :runtime
80
77
  prerelease: false
81
78
  version_requirements: !ruby/object:Gem::Requirement
82
79
  requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: '4.0'
86
- - - "<"
80
+ - - "~>"
87
81
  - !ruby/object:Gem::Version
88
- version: '6.0'
82
+ version: '5.14'
89
83
  - !ruby/object:Gem::Dependency
90
84
  name: moxml
91
85
  requirement: !ruby/object:Gem::Requirement