fix(schema): require a list or union to declare its member types (#145)
A list simple type must draw its item type from exactly one of an itemType attribute or an inline simpleType child; neither, or both, is invalid. A union must declare at least one member type through a memberTypes attribute or an inline simpleType child; an empty union declares none (src-simple-type.2/.3). XSTS invalid-schemas-accepted 215 to 214, no other bucket moved.
This commit is contained in:
parent
8420c7e2aa
commit
d2438a957a
@ -22,6 +22,8 @@ Second pre-release. Continues the W3C XSTS schema-validity campaign: **invalid-s
|
||||
|
||||
### Fixed
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `list` simple type must draw its item type from exactly one of an `itemType` attribute or an inline `simpleType` child (neither, or both, is invalid), and a `union` must declare at least one member type through a `memberTypes` attribute or an inline `simpleType` child (an empty `union` declares none), per `src-simple-type.2`/`.3`. Caught one invalid schema: invalid-schemas-accepted 215 → 214, no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a simple type without its own `final` attribute now inherits the schema's `finalDefault` as its `{final}` property (XSD 1.0 Schemas §3.14.2), so `finalDefault="list"` or `"union"` blocks the matching list-item or union-member derivation just as an explicit `final` would. An explicit `final=""` still overrides the default back to no restriction. Caught two invalid schemas: invalid-schemas-accepted 217 → 215, no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `pattern` facet whose regular expression ends mid-token is now rejected as a schema-validity error. A trailing `\` with no character to escape (`a\`) raises `RegexError.incompleteEscape`, and a `[` character class the expression ends before closing with `]` (`a[`, `[a[:xyz:`) raises `RegexError.unterminatedClass`; both are unambiguously invalid rather than an engine limitation on an otherwise-valid pattern, so they reject. Caught thirteen invalid schemas: invalid-schemas-accepted 230 → 217, no other bucket moved.
|
||||
|
||||
@ -33,6 +33,19 @@ extension PureXML.Schema.XSDParser {
|
||||
if !isForeign, isListOrUnionContainingList(item) {
|
||||
errors.append("the item type of a list must be atomic or union of atomic, not a list or union containing list")
|
||||
}
|
||||
// src-simple-type.2: a list has its item type from EITHER the
|
||||
// itemType attribute OR an inline simpleType child, never both and
|
||||
// never neither.
|
||||
if hasItemTypeAttribute(node) == hasSimpleTypeChild(node) {
|
||||
errors.append("a list must have either an 'itemType' attribute or an inline simpleType child, but not both")
|
||||
}
|
||||
}
|
||||
|
||||
// src-simple-type.3: a union draws its members from a memberTypes
|
||||
// attribute, inline simpleType children, or both, so it must declare at
|
||||
// least one of them (an empty union has no member type definitions).
|
||||
if isEmptyUnion(node, local) {
|
||||
errors.append("a union must declare at least one member type, through 'memberTypes' or an inline simpleType child")
|
||||
}
|
||||
|
||||
for child in PureXML.Schema.XSDNode.elementChildren(node) {
|
||||
@ -44,6 +57,22 @@ extension PureXML.Schema.XSDParser {
|
||||
return errors
|
||||
}
|
||||
|
||||
/// A `union` element in the schema namespace that declares no member types at
|
||||
/// all: neither a `memberTypes` attribute nor an inline `simpleType` child.
|
||||
private static func isEmptyUnion(_ node: XSDTree, _ local: String?) -> Bool {
|
||||
node.name?.namespaceURI == xsdNamespace && local == "union"
|
||||
&& PureXML.Schema.XSDNode.attribute(node, "memberTypes") == nil
|
||||
&& !hasSimpleTypeChild(node)
|
||||
}
|
||||
|
||||
private static func hasItemTypeAttribute(_ node: XSDTree) -> Bool {
|
||||
PureXML.Schema.XSDNode.attribute(node, "itemType") != nil
|
||||
}
|
||||
|
||||
private static func hasSimpleTypeChild(_ node: XSDTree) -> Bool {
|
||||
PureXML.Schema.XSDNode.elementChildren(node).contains { PureXML.Schema.XSDNode.localName($0) == "simpleType" }
|
||||
}
|
||||
|
||||
private static func inScopeNamespaceBindings(of node: XSDTree) -> [String: String] {
|
||||
var bindings: [String: String] = [:]
|
||||
var current: XSDTree? = node
|
||||
|
||||
@ -100,8 +100,13 @@ struct XSTSSuiteTests {
|
||||
/// type declares no `final` of its own (so `finalDefault="list"`/`"union"`
|
||||
/// blocks the matching list/union derivation) then caught two more invalid
|
||||
/// schemas: invalid-schemas accepted 217 → 215, no other bucket moved.
|
||||
/// Requiring a `list` to draw its item type from exactly one of `itemType` or an
|
||||
/// inline simpleType child, and a `union` to declare at least one member through
|
||||
/// `memberTypes` or an inline simpleType child (src-simple-type.2/.3), then
|
||||
/// caught one more invalid schema: invalid-schemas accepted 215 → 214, no other
|
||||
/// bucket moved.
|
||||
private let knownSchemaValidRejected = 1
|
||||
private let knownSchemaInvalidAccepted = 215
|
||||
private let knownSchemaInvalidAccepted = 214
|
||||
private let knownInstanceValidRejected = 3
|
||||
private let knownInstanceInvalidAccepted = 132
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user