moxml 0.6.23 → 0.6.25

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: fb2d61022821c9c81d11371a5d97ef32040c040039d54428548b7996cf7b63cb
4
- data.tar.gz: '09b7a98f8e4b9812846ff9db5461c99da69b7f9315cf27c1be85373c6e2d1df6'
3
+ metadata.gz: '0590905c59de33d1b7f4f69832c536f51d542a5763c9c2132ec5ac2ef86dae05'
4
+ data.tar.gz: 1f3667cdcac77a2da739eca0ea1cb006326848a53b65443bac3da8262878f0de
5
5
  SHA512:
6
- metadata.gz: d42184c7983090bec857d3295da85372b99a93814999eb53c28f47789d8025f97c37f5d3c26604a8b32c436a03e7541128b0bcbfedf24b929ef0e0d4c040e7d1
7
- data.tar.gz: '096f216f8e8b14623b195d099e6c6f19583ba053c13bd63a1d66728ea33e65643b7064c17f2b5b955d61f1bccc070eaa09d25b5a2effd1567ae53c31adae224e'
6
+ metadata.gz: 51fe34fd975820f29670ecbf2885e3ea7d072aa02767a1d7d6520f80ded5af1a215b4a7f9f970eabfb5dee8233b5858599f0cd80316d16811d58b55a607a7e33
7
+ data.tar.gz: 2743c2305ab9344eca884130944911e198f495151696d0cca075c0b6318feff7ae2e6c46e272a0f2f00632e57d90dd3537d478687c0b400d211504a66329eeaf
@@ -3670,6 +3670,12 @@ module Moxml
3670
3670
  end
3671
3671
 
3672
3672
  def add_child_impl(parent, child)
3673
+ # TextSegment value objects (the entity-retention split
3674
+ # runs) are the adapter's own parse output - attaching one
3675
+ # attaches its text content (#606): the raw value object
3676
+ # would fall through to the binding, which rejects anything
3677
+ # that is not a native Node or String.
3678
+ child = child.content.to_s if child.is_a?(CustomizedLeptris::TextSegment)
3673
3679
  # Same-document Identity append — the builder hot path. One
3674
3680
  # document pair decides the verdict: the pin, the absorb
3675
3681
  # checks and the binding bridges only exist for
data/lib/moxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.6.23"
4
+ VERSION = "0.6.25"
5
5
  end
@@ -504,7 +504,11 @@ module Moxml
504
504
  end
505
505
 
506
506
  LEXICAL_MESSAGE = /\A(?:element|attribute) '([^']+)' @\d+:\d+: (element|attribute) '([^']+)': lexical value does not match its type\z/
507
- CONTENT_MODEL_MESSAGE = /\Aelement '([^']+)' @\d+:\d+: element '([^']+)': children do not match the content model \(at '([^']+)'\)\z/
507
+ # The engine emits the `(at '...')` particle anchor only when
508
+ # the walk names it; the same-named global/local collision
509
+ # (#594) rejects without one. The at-clause is optional; the
510
+ # witness walk carries the per-particle proof either way.
511
+ CONTENT_MODEL_MESSAGE = /\Aelement '([^']+)' @\d+:\d+: element '([^']+)': children do not match the content model(?: \(at '([^']+)'\))?\z/
508
512
 
509
513
  private_constant :LEXICAL_MESSAGE, :CONTENT_MODEL_MESSAGE
510
514
 
@@ -552,34 +556,42 @@ module Moxml
552
556
  # once, and the reported offender is a substitution member
553
557
  # realized at some position. Anything else leaves the
554
558
  # engine's answer standing.
559
+ # The occurrence-aware walk (#594): each particle consumes the
560
+ # children it binds, honoring its min/max; optional particles
561
+ # (the lax xs:any) skip. A same-named local particle binds its
562
+ # own position (XSD §3.3.3 shadowing) — the engine's
563
+ # same-named global collapse is exactly what this walk
564
+ # refutes. Only removes false rejections: every accepted
565
+ # document matches the local content model name-for-name.
555
566
  def sequence_valid?(element, index, offender)
556
567
  model = index.contents[qname(element)]
557
568
  return false unless model&.pure_sequence
558
569
 
559
570
  particles = model.particles
560
571
  children = child_elements(element)
561
- return false if children.empty? || children.size != particles.size
562
572
 
563
573
  resolved = false
564
- children.each_with_index do |child, position|
565
- particle_name, min, max = particles[position]
566
- child_qname = qname(child)
567
- return false unless exactly_once?(min, max)
568
-
569
- if child_qname == particle_name
570
- next
571
- elsif index.substitution_members.fetch(particle_name, [])
572
- .include?(child_qname)
573
- resolved = true
574
- else
575
- return false
574
+ cursor = 0
575
+ particles.each do |(particle_name, min, max)|
576
+ consumed = 0
577
+ while cursor < children.size &&
578
+ particle_binds?(children[cursor], particle_name, index) &&
579
+ (max == :unbounded || consumed < max)
580
+ consumed += 1
581
+ cursor += 1
576
582
  end
583
+ return false if consumed < min
584
+
585
+ resolved = true if consumed >= 1
577
586
  end
578
- resolved && offender_realized?(children, offender, index)
587
+ return false if cursor != children.size
588
+
589
+ offender ? (resolved && offender_realized?(children, offender, index)) : true
579
590
  end
580
591
 
581
- def exactly_once?(min, max)
582
- min <= 1 && (max == :unbounded || max >= 1)
592
+ def particle_binds?(child, particle_name, index)
593
+ qname(child) == particle_name ||
594
+ index.substitution_members.fetch(particle_name, []).include?(qname(child))
583
595
  end
584
596
 
585
597
  def offender_realized?(children, offender, index)
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # lutaml/moxml#606: under entity-reference retention, parsing
6
+ # marker-bearing text mints CustomizedLeptris::TextSegment value
7
+ # objects as the native children behind Wrappers::Text. Re-attaching
8
+ # such a parsed child via add_child crashed - the attach path handed
9
+ # the raw value object to the binding, which accepts only native
10
+ # Nodes and Strings. The adapter's own parse output must be accepted
11
+ # by its own attach path: a TextSegment attaches as its text content.
12
+ RSpec.describe "TextSegment attach under entity retention (#606)" do
13
+ let(:ctx) { Moxml.new(:leptris) }
14
+
15
+ before do
16
+ ctx.config.restore_entities = true
17
+ end
18
+
19
+ it "re-attaches parsed marker-split children to another element" do
20
+ parsed = ctx.parse(
21
+ "<fragment>alpha&nbsp;beta&mdash;gamma<child a=\"1\"/></fragment>",
22
+ )
23
+ target = parsed.document.create_element("t")
24
+
25
+ parsed.root.children.each { |c| target.add_child(c) }
26
+
27
+ names = target.children.map { |c| c.respond_to?(:name) ? c.name : nil }
28
+ expect(names).to include("child")
29
+ expect(target.children.count).to be_positive
30
+ end
31
+
32
+ it "preserves the re-attached text runs verbatim" do
33
+ parsed = ctx.parse("<fragment>alpha&nbsp;beta&mdash;gamma</fragment>")
34
+ target = parsed.document.create_element("t")
35
+
36
+ parsed.root.children.each { |c| target.add_child(c) }
37
+
38
+ combined = target.children.to_a.join
39
+ expect(combined).to include("alpha")
40
+ expect(combined).to include("beta")
41
+ expect(combined).to include("gamma")
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # moxml#594: a GLOBAL element `e` and a LOCAL element `e` coexist in
6
+ # one schema (XSD §3.3.3: local declarations shadow within their
7
+ # scope). The engine's automaton binds all same-named children to ONE
8
+ # declaration, rejecting documents whose local `e` content is valid
9
+ # against the LOCAL type; the occurrence-aware witness walk carries
10
+ # the per-particle proof and dismisses the false rejection.
11
+ RSpec.describe "same-named global/local element declarations" do
12
+ let(:ctx) { Moxml.new(:leptris) }
13
+ let(:schema) do
14
+ ctx.xsd(<<~XSD)
15
+ <?xml version="1.0"?>
16
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
17
+ <xs:complexType name="zing">
18
+ <xs:sequence>
19
+ <xs:element name="e" type="xs:integer"/>
20
+ <xs:element name="f" type="xs:integer"/>
21
+ <xs:any namespace="##local" processContents="lax"/>
22
+ </xs:sequence>
23
+ </xs:complexType>
24
+ <xs:element name="doc" type="zing"/>
25
+ <xs:element name="e" type="xs:positiveInteger"/>
26
+ </xs:schema>
27
+ XSD
28
+ end
29
+
30
+ before do
31
+ skip "leptris adapter unavailable" unless
32
+ Moxml::Adapter::Leptris::XSD_SUPPORTED
33
+ end
34
+
35
+ it "binds the local particle for the local position" do
36
+ expect(schema.validate("<doc><e>-12</e><f>42</f></doc>")).to eq([])
37
+ end
38
+
39
+ it "keeps rejecting a local e that is not an integer" do
40
+ expect(schema.validate("<doc><e>oops</e><f>42</f></doc>")).not_to be_empty
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.23
4
+ version: 0.6.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -507,6 +507,7 @@ files:
507
507
  - spec/moxml/adapter/leptris_sax_records_spec.rb
508
508
  - spec/moxml/adapter/leptris_spec.rb
509
509
  - spec/moxml/adapter/leptris_strict_mismatch_spec.rb
510
+ - spec/moxml/adapter/leptris_textsegment_attach_spec.rb
510
511
  - spec/moxml/adapter/leptris_xpath_bulk_rows_spec.rb
511
512
  - spec/moxml/adapter/leptris_xpath_identity_spec.rb
512
513
  - spec/moxml/adapter/libxml_internals_spec.rb
@@ -651,6 +652,7 @@ files:
651
652
  - spec/moxml/xsd_regex_conformance_spec.rb
652
653
  - spec/moxml/xsd_regex_spec.rb
653
654
  - spec/moxml/xsd_release_spec.rb
655
+ - spec/moxml/xsd_same_named_elements_spec.rb
654
656
  - spec/moxml/xsd_set_spec.rb
655
657
  - spec/moxml/xsd_spec.rb
656
658
  - spec/moxml/xsd_substitution_spec.rb