fix(schema): a local complexType must be anonymous; invalid-schemas-accepted 81 to 80 (#145)
A complexType nested in an element is a local (anonymous) type definition and may not carry a name attribute; only a top-level complexType (a child of schema, or a redefine redefinition) is named. localComplexTypeNameErrors flags a named complexType whose parent is an element, wired into the structure-walk validation. XSTS: invalid-schemas-accepted 81 to 80 (ctA042), valid-schemas-rejected held at 0, no other bucket moved.
This commit is contained in:
parent
059763f5e9
commit
75dd044d93
@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `complexType` nested in an `element` is a local, anonymous type and may not carry a `name` attribute; only a top-level `complexType` (or a `redefine` redefinition) is named. invalid-schemas-accepted 81 → 80, no false positive (valid-schemas-rejected held at 0), no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#161): a type inside `xs:redefine` must restrict or extend the type it redefines, which lives in the redefining schema's own target namespace (`src-redefine.5`). A derivation base bound to a different namespace, such as an imported type that happens to share the redefined type's local name, is not a self-redefinition and is now rejected; the previous check compared local names only and accepted it. A base with no resolvable namespace is left alone, so an unprefixed or own-namespace self-reference is unaffected. invalid-schemas-accepted 84 → 81, no false positive (valid-schemas-rejected held at 0; differential PureXML-stricter unchanged at 87 over 9618 schemas), no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#161): an `import`'s `namespace` attribute must equal the `targetNamespace` of the schema document it resolves to (`src-import.3.1`/`3.2`): both present and equal, or both absent. Importing a no-namespace document under a declared namespace, or a document whose target namespace differs from the declared one, is now rejected. Checked only when the `schemaLocation` resolves to a loaded schema (an unresolved import is the processor's choice and not an error); imports keep their own target namespace, so no chameleon adjustment applies. invalid-schemas-accepted 87 → 84, no false positive (valid-schemas-rejected held at 0; differential PureXML-stricter unchanged at 87 over 9618 schemas), no other bucket moved.
|
||||
|
||||
@ -130,6 +130,7 @@ extension PureXML.Schema.XSDParser {
|
||||
case "complexType":
|
||||
errors += elementDeclsConsistentErrors(node)
|
||||
errors += complexTypeOrderErrors(node)
|
||||
errors += localComplexTypeNameErrors(node)
|
||||
case "complexContent":
|
||||
errors += complexContentOrderErrors(node)
|
||||
case "simpleContent":
|
||||
|
||||
@ -227,6 +227,18 @@ extension PureXML.Schema.XSDParser {
|
||||
return errors
|
||||
}
|
||||
|
||||
/// A `complexType` nested in an `element` is a local (anonymous) type and must
|
||||
/// not carry a `name`; only a top-level `complexType` (a child of `schema`, or a
|
||||
/// `redefine` redefinition) is named. A local type definition has no name.
|
||||
static func localComplexTypeNameErrors(_ node: XSDTree) -> [String] {
|
||||
guard PureXML.Schema.XSDNode.attribute(node, "name") != nil,
|
||||
let parent = node.parent,
|
||||
parent.name?.namespaceURI == xsdNamespace,
|
||||
PureXML.Schema.XSDNode.localName(parent) == "element"
|
||||
else { return [] }
|
||||
return ["a complexType nested in an element must not have a 'name' attribute"]
|
||||
}
|
||||
|
||||
/// The content model of an identity constraint (`unique`/`key`/`keyref`) is
|
||||
/// `(annotation?, selector, field+)`: exactly one `selector`, then one or more
|
||||
/// `field`s, in that order. A `field` before the `selector`, a second
|
||||
|
||||
@ -371,4 +371,24 @@ struct SchemaStructureOrderTests {
|
||||
</xs:group>
|
||||
"""#))
|
||||
}
|
||||
|
||||
/// A complexType nested in an element is a local (anonymous) type and must not
|
||||
/// carry a name; only a top-level complexType is named.
|
||||
@Test("a local complexType may not have a name")
|
||||
func test_localComplexTypeMustBeAnonymous() {
|
||||
#expect(rejects(#"""
|
||||
<xs:element name="e">
|
||||
<xs:complexType name="fooType">
|
||||
<xs:sequence><xs:element name="c" type="xs:string"/></xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
"""#))
|
||||
// A top-level named complexType, and an anonymous local one, are both valid.
|
||||
try? compile(#"<xs:complexType name="t"><xs:sequence/></xs:complexType>"#)
|
||||
#expect(!rejects(#"""
|
||||
<xs:element name="e">
|
||||
<xs:complexType><xs:sequence><xs:element name="c" type="xs:string"/></xs:sequence></xs:complexType>
|
||||
</xs:element>
|
||||
"""#))
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,9 +151,10 @@ struct XSTSSuiteTests {
|
||||
/// an import's namespace must equal the imported targetNamespace (src-import.3)
|
||||
/// 87->84; and a redefined type must derive from the type it redefines in the
|
||||
/// redefining schema's own namespace, not a same-named foreign one (src-redefine.5)
|
||||
/// 84->81.
|
||||
/// 84->81; and a complexType nested in an element must be anonymous (no name)
|
||||
/// 81->80.
|
||||
private let knownSchemaValidRejected = 0
|
||||
private let knownSchemaInvalidAccepted = 81
|
||||
private let knownSchemaInvalidAccepted = 80
|
||||
private let knownInstanceValidRejected = 0
|
||||
private let knownInstanceInvalidAccepted = 133
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user