moxml 0.6.24 → 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: 90baa6c32eb44a50601f1d9784e50bfa00c4b2d172d1ebdbef30ffbba80c1fbd
4
- data.tar.gz: 2eaf0b64683cb001d40585752601ec6f41af5f88339744c108370e51404ea508
3
+ metadata.gz: '0590905c59de33d1b7f4f69832c536f51d542a5763c9c2132ec5ac2ef86dae05'
4
+ data.tar.gz: 1f3667cdcac77a2da739eca0ea1cb006326848a53b65443bac3da8262878f0de
5
5
  SHA512:
6
- metadata.gz: 811ab8695281e1d5bebe4abdc3a2ab70e518aeb799fd4300c6b7a26d64d965188f3734fcd970251f06a1fab0e317028ee1af817362415ce8aecf0c12f22ab939
7
- data.tar.gz: 7243257da8297195ebbc3039e21557033fc299b18b8e77c9eb796878e8e57f20f483378f218347e070f6eabd8b7fb316f274dd275de9fb150c75a65d3bcf2f80
6
+ metadata.gz: 51fe34fd975820f29670ecbf2885e3ea7d072aa02767a1d7d6520f80ded5af1a215b4a7f9f970eabfb5dee8233b5858599f0cd80316d16811d58b55a607a7e33
7
+ data.tar.gz: 2743c2305ab9344eca884130944911e198f495151696d0cca075c0b6318feff7ae2e6c46e272a0f2f00632e57d90dd3537d478687c0b400d211504a66329eeaf
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.24"
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,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.24
4
+ version: 0.6.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -652,6 +652,7 @@ files:
652
652
  - spec/moxml/xsd_regex_conformance_spec.rb
653
653
  - spec/moxml/xsd_regex_spec.rb
654
654
  - spec/moxml/xsd_release_spec.rb
655
+ - spec/moxml/xsd_same_named_elements_spec.rb
655
656
  - spec/moxml/xsd_set_spec.rb
656
657
  - spec/moxml/xsd_spec.rb
657
658
  - spec/moxml/xsd_substitution_spec.rb