From ceca006c450ba342f829adb3c6b6b28314352243 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Wed, 17 Jun 2026 18:46:04 +0200 Subject: [PATCH] fix(schema): a restriction's attribute wildcard must subset the base's (#145) cos-ct-restricts.4: a base type with no attribute wildcard admits none (so a restriction may not introduce one), and a wider namespace constraint such as ##any over ##other, or a weakened processContents, is not a subset. Reuses the wildcard subset check (ParticleRestriction.narrows, now internal). XSTS invalid-schemas-accepted 131 to 128, no other bucket moved. --- CHANGELOG.md | 2 ++ Sources/Schema/ParticleRestriction.swift | 5 ++++- Sources/Schema/SchemaAttributeRestriction.swift | 13 +++++++++++++ Tests/XSTSSuiteTests.swift | 6 +++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2aff77..c6c64b6 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 complexContent restriction's own attribute wildcard must be a subset of the base's (`cos-ct-restricts.4`). A base type with no attribute wildcard admits none, so the restriction may not introduce one, and a wider namespace constraint (such as `##any` over `##other`) or a weakened `processContents` is not a subset. Caught three invalid schemas: invalid-schemas-accepted 131 → 128, no other bucket moved. + - XSTS invalid-schemas-accepted (#145): a complexContent restriction may not add an attribute the base type never permitted. An attribute the restriction declares that has no matching base attribute use must be admitted by the base's `anyAttribute` wildcard (`cos-ct-restricts.3`); for example a no-namespace attribute is not admitted by a `##other` wildcard. A `prohibited` declaration (which removes an attribute) stays valid. Caught one invalid schema: invalid-schemas-accepted 132 → 131, no other bucket moved. - XSTS invalid-schemas-accepted (#145): a namespace value may not be the empty string. `` and `` are rejected, since a namespace name must be a non-empty `anyURI` (omitting the attribute, for no target namespace or a no-namespace import, stays valid). Caught two invalid schemas: invalid-schemas-accepted 134 → 132, no other bucket moved. diff --git a/Sources/Schema/ParticleRestriction.swift b/Sources/Schema/ParticleRestriction.swift index 50972ad..52d4b44 100644 --- a/Sources/Schema/ParticleRestriction.swift +++ b/Sources/Schema/ParticleRestriction.swift @@ -267,7 +267,10 @@ extension PureXML.Schema { } /// Whether the restricted wildcard admits no namespace the base refuses. - private static func narrows(_ restricted: Wildcard, _ base: Wildcard) -> Bool { + /// Whether `restricted` is a valid subset of `base` (Wildcard Subset): its + /// processContents is at least as strong and its namespace constraint is + /// narrower or equal. Shared with attribute-wildcard restriction. + static func narrows(_ restricted: Wildcard, _ base: Wildcard) -> Bool { // 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. diff --git a/Sources/Schema/SchemaAttributeRestriction.swift b/Sources/Schema/SchemaAttributeRestriction.swift index e732179..daba66a 100644 --- a/Sources/Schema/SchemaAttributeRestriction.swift +++ b/Sources/Schema/SchemaAttributeRestriction.swift @@ -34,6 +34,19 @@ extension PureXML.Schema.XSDParser { errors.append(message) } } + // cos-ct-restricts.4: a restriction's own attribute wildcard must be a + // subset of the base's. A base with no wildcard admits none, so the + // restriction may not introduce one (ctO005); a wider namespace + // constraint, such as `##any` over `##other`, is not a subset (ctO007). + if let derivedWildcard = attributeWildcard(under: restriction, context) { + if let baseWildcard = complex.attributeWildcard { + if !PureXML.Schema.ParticleRestriction.narrows(derivedWildcard, baseWildcard) { + errors.append("the restriction's attribute wildcard is not a subset of the base type's attribute wildcard") + } + } else { + errors.append("a restriction may not introduce an attribute wildcard that the base type does not have") + } + } } return errors } diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift index 84a29b5..5008e59 100644 --- a/Tests/XSTSSuiteTests.swift +++ b/Tests/XSTSSuiteTests.swift @@ -115,8 +115,12 @@ struct XSTSSuiteTests { /// to be admitted by the base's attribute wildcard (cos-ct-restricts.3) then /// caught one more invalid schema: invalid-schemas accepted 132 → 131, no other /// bucket moved. + /// Requiring a restriction's own attribute wildcard to be a subset of the base's + /// (cos-ct-restricts.4: a base without one admits none; `##any` over `##other` is + /// not a subset) then caught three more invalid schemas: invalid-schemas accepted + /// 131 → 128, no other bucket moved. private let knownSchemaValidRejected = 1 - private let knownSchemaInvalidAccepted = 131 + private let knownSchemaInvalidAccepted = 128 private let knownInstanceValidRejected = 3 private let knownInstanceInvalidAccepted = 132