fix(schema): a wildcard restriction may not weaken processContents (#145)
A restricting xs:any must have processContents at least as strong as the base wildcard's (strict > lax > skip; Wildcard Subset, XSD 1.0 sec 3.10.6), in addition to narrowing the namespace constraint. XSTS invalid-schemas-accepted 137 to 134, no other bucket moved.
This commit is contained in:
parent
903345e764
commit
30421073a1
@ -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 `<simpleContent><restriction>` 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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user