fix(schema): check RecurseAsIfGroup occurrence in particle restriction (#145)
An element restricting a base model group is treated as a synthetic group with
minOccurs=maxOccurs=1 holding the element (XSD 1.0 sec 3.9.6), so its {1,1}
occurrence must be within the base group's range: a base group that must occur
two or more times cannot be restricted to a single element. The element's own
occurrence is still matched against the base branch it maps to, so an optional
element restricting a once-or-more base group stays valid.
XSTS invalid-schemas-accepted 181 to 179, no other bucket moved.
This commit is contained in:
parent
817d3e46df
commit
c3876a261f
@ -22,6 +22,8 @@ Second pre-release. Continues the W3C XSTS schema-validity campaign: **invalid-s
|
||||
|
||||
### Fixed
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): the RecurseAsIfGroup case of Particle Valid (Restriction) now checks occurrence. An element restricting a base model group is treated as a synthetic group with `minOccurs=maxOccurs=1` holding the element (XSD 1.0 §3.9.6), so a base group that must occur two or more times cannot be restricted to a single element. The element's own occurrence is still matched against the base branch it maps to, so an optional element restricting a once-or-more base group stays valid (no false rejection). Caught two invalid schemas: invalid-schemas-accepted 181 → 179, no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `redefine` is now checked against the schema it redefines once that schema is loaded: every component the `redefine` names (a `complexType`, `simpleType`, `group`, or `attributeGroup`) must have a same-kind component of the same name in the redefined schema (`src-redefine.6`/`7.2.1`), and the same component may not be redefined twice in one `redefine` (`src-redefine.7.2.2`). A redefinition naming a component that does not exist there, or a duplicate redefinition, is rejected. The check runs only when the redefined document was loaded through a `schemaLoader`, so a stand-alone schema is unaffected. Caught two invalid schemas: invalid-schemas-accepted 183 → 181, no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): an element or attribute `default`/`fixed` value constraint is now validated against an inline type (an inline `simpleType`, or an inline complex type with `simpleContent`) just as it already was against a named `type` reference, so a non-numeric `default` on a decimal-based inline type is rejected. Validated against the simpleContent base's value space, so only a clear value-space mismatch is flagged. Caught two invalid schemas: invalid-schemas-accepted 185 → 183, no other bucket moved.
|
||||
|
||||
@ -75,11 +75,16 @@ extension PureXML.Schema {
|
||||
case let (.wildcard(restrictedWildcard), .wildcard(baseWildcard)):
|
||||
return rangeSubsumed(restricted, base) && narrows(restrictedWildcard, baseWildcard)
|
||||
case let (.element, .group(baseGroup)):
|
||||
// RecurseAsIfGroup: the lone element, as a one-particle sequence,
|
||||
// against the base group. The element's occurrence is matched against
|
||||
// a base member inside `groupValid`, not against the base group's own
|
||||
// occurrence, so no outer `rangeSubsumed` here.
|
||||
return groupValid(Group(compositor: .sequence, particles: [restricted]), baseGroup, types, derivation)
|
||||
// RecurseAsIfGroup (XSD 1.0 §3.9.6): the element is treated as a group
|
||||
// with {min,max}=1,1 holding the element. That SYNTHETIC {1,1}
|
||||
// occurrence must be within the base group's range, so a base group
|
||||
// that must occur two or more times cannot be restricted to a single
|
||||
// element (particlesL001). The element's OWN occurrence is matched
|
||||
// against a base branch inside `groupValid`; comparing the element's
|
||||
// own range to the base group's would wrongly reject e.g. an optional
|
||||
// element restricting a once-or-more base group.
|
||||
return rangeWithinWildcard(derivedMin: 1, derivedMax: 1, wildcardMin: base.minOccurs, wildcardMax: base.maxOccurs)
|
||||
&& groupValid(Group(compositor: .sequence, particles: [restricted]), baseGroup, types, derivation)
|
||||
case let (.group, .element(baseName, _, baseTypeName, _)):
|
||||
// The mirror of RecurseAsIfGroup, by the same cardinality argument as
|
||||
// group/wildcard: a base element accepts only its own name, its own
|
||||
|
||||
@ -82,8 +82,13 @@ struct XSTSSuiteTests {
|
||||
/// Rejecting a `redefine` that redefines the same component twice (src-redefine.7.2.2)
|
||||
/// then caught one more invalid schema: invalid-schemas accepted 182 → 181, no
|
||||
/// other bucket moved.
|
||||
/// Checking the RecurseAsIfGroup occurrence in Particle-Valid-Restriction (an
|
||||
/// element restricting a base group is a synthetic {1,1} group, so a base group
|
||||
/// that must occur 2+ times cannot be restricted to one element; §3.9.6) then
|
||||
/// caught two more invalid schemas: invalid-schemas accepted 181 → 179, no other
|
||||
/// bucket moved.
|
||||
private let knownSchemaValidRejected = 1
|
||||
private let knownSchemaInvalidAccepted = 181
|
||||
private let knownSchemaInvalidAccepted = 179
|
||||
private let knownInstanceValidRejected = 3
|
||||
private let knownInstanceInvalidAccepted = 132
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user