diff --git a/CHANGELOG.md b/CHANGELOG.md index cb8517e..04ce157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ Second pre-release. Continues the W3C XSTS schema-validity campaign: **invalid-s ### Fixed +- XSTS invalid-schemas-accepted (#145): a wildcard restriction may not weaken `processContents`. When a complex type restricts another, a restricting `xs:any` must have a `processContents` at least as strong as the base wildcard's (`strict` > `lax` > `skip`; Wildcard Subset, §3.10.6), in addition to narrowing the namespace. Caught three invalid schemas: invalid-schemas-accepted 137 → 134, no other bucket moved. + - XSTS invalid-schemas-accepted (#145): a `simpleContent` restriction's base must be a complex type. Restricting a built-in (`xs:integer`, `xs:anySimpleType`) or a user `simpleType` through `` is rejected (`src-ct.2`); a complex type with simple content is built by extending a simple type, not by restricting one. Caught five invalid schemas: invalid-schemas-accepted 142 → 137, no other bucket moved. - XSTS invalid-schemas-accepted (#145): Particle Valid (Restriction) now enforces the NameAndTypeOK nillable clause. A restricting element may not be `nillable` unless the base element it restricts is also nillable. Caught two invalid schemas: invalid-schemas-accepted 144 → 142, no other bucket moved. diff --git a/Sources/Schema/ParticleRestriction.swift b/Sources/Schema/ParticleRestriction.swift index 9228471..50972ad 100644 --- a/Sources/Schema/ParticleRestriction.swift +++ b/Sources/Schema/ParticleRestriction.swift @@ -268,7 +268,13 @@ extension PureXML.Schema { /// Whether the restricted wildcard admits no namespace the base refuses. private static func narrows(_ restricted: Wildcard, _ base: Wildcard) -> Bool { - switch (restricted.namespace, base.namespace) { + // Wildcard Subset (XSD 1.0 §3.10.6): the restriction's processContents + // must be identical to or STRONGER than the base's (strict > lax > skip); + // a restriction may not weaken validation. Namespace narrowing is below. + guard processContentsRank(restricted.processContents) >= processContentsRank(base.processContents) else { + return false + } + return switch (restricted.namespace, base.namespace) { case (_, .any): true case (.other, .other): @@ -286,6 +292,16 @@ extension PureXML.Schema { lhs.localName == rhs.localName && (lhs.namespaceURI ?? "") == (rhs.namespaceURI ?? "") } + /// Validation strength of a wildcard's `processContents`, for the Wildcard + /// Subset rule: `strict` is stronger than `lax` is stronger than `skip`. + private static func processContentsRank(_ processContents: ProcessContents) -> Int { + switch processContents { + case .skip: 0 + case .lax: 1 + case .strict: 2 + } + } + /// NameAndTypeOK value-constraint clause: when the base element is `fixed`, /// the restricting element must also be `fixed` to the same value (compared in /// the base type's value space, so `1` and `01` match). A base with no fixed diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift index 0a7c471..ef7e4a0 100644 --- a/Tests/XSTSSuiteTests.swift +++ b/Tests/XSTSSuiteTests.swift @@ -105,8 +105,11 @@ struct XSTSSuiteTests { /// Requiring a `simpleContent` restriction's base to be a complex type, not a /// built-in or user simple type (src-ct.2), then caught five more invalid /// schemas: invalid-schemas accepted 142 → 137, no other bucket moved. + /// Requiring a restricting wildcard's `processContents` to be at least as strong + /// as the base's (strict > lax > skip; Wildcard Subset §3.10.6) then caught three + /// more invalid schemas: invalid-schemas accepted 137 → 134, no other bucket moved. private let knownSchemaValidRejected = 1 - private let knownSchemaInvalidAccepted = 137 + private let knownSchemaInvalidAccepted = 134 private let knownInstanceValidRejected = 3 private let knownInstanceInvalidAccepted = 132