diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a68613..e21a396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- XSTS invalid-schemas-accepted (#145): an `xs:include` and `xs:redefine` require a `schemaLocation` attribute (only `xs:import`'s is optional); one declared without it is rejected. invalid-schemas-accepted 71 → 69, no false positive (valid-schemas-rejected held at 0; a required-attribute check with no name resolution cannot over-reject), no other bucket moved. + - XSTS invalid-schemas-accepted (#161): a schema referenced by `xs:redefine` must have the same `targetNamespace` as the redefining schema, or none (chameleon), exactly as for `xs:include`; redefining a different-namespace schema is rejected. The existing include-namespace-matching check now also covers `redefine`, selecting the loaded redefined schema document (not the redefine wrapper) so its real target namespace is compared. invalid-schemas-accepted 74 → 71, no false positive (valid-schemas-rejected held at 0; an adversarial review confirmed same-namespace, chameleon, and no-namespace redefines are not flagged), no other bucket moved. - XSTS invalid-schemas-accepted (#145): an identity-constraint `selector`/`field` xpath may not use an undeclared namespace prefix. Every prefix in a name test must be a declared `xmlns:` prefix in scope (the implicit `xml` prefix excepted); a `selector`/`field` whose xpath names an unbound prefix is rejected. invalid-schemas-accepted 77 → 75, no false positive (valid-schemas-rejected held at 0; an adversarial review confirmed declared prefixes on the schema root or any ancestor resolve correctly), no other bucket moved. diff --git a/Sources/Schema/SchemaStructure.swift b/Sources/Schema/SchemaStructure.swift index 0d45538..9da4321 100644 --- a/Sources/Schema/SchemaStructure.swift +++ b/Sources/Schema/SchemaStructure.swift @@ -147,8 +147,7 @@ extension PureXML.Schema.XSDParser { private static func structuralErrors(_ node: XSDTree, local: String, names: [String]) -> [String] { switch local { - case "any", "anyAttribute": - wildcardNamespaceErrors(node) + case "any", "anyAttribute": wildcardNamespaceErrors(node) case "restriction": restrictionErrors(node, names: names) case "list": @@ -157,6 +156,8 @@ extension PureXML.Schema.XSDParser { schemaChildrenOrderErrors(names) case "import": importErrors(node) + case "include", "redefine": + PureXML.Schema.XSDNode.attribute(node, "schemaLocation") == nil ? ["an '\(local)' must have a 'schemaLocation' attribute"] : [] default: containerStructuralErrors(node, local: local, names: names) } diff --git a/Tests/SchemaStructureTests.swift b/Tests/SchemaStructureTests.swift index a3a65c4..dc03c5b 100644 --- a/Tests/SchemaStructureTests.swift +++ b/Tests/SchemaStructureTests.swift @@ -372,6 +372,14 @@ struct SchemaStructureOrderTests { """#)) } + /// An xs:include and xs:redefine require a schemaLocation attribute (only + /// xs:import's is optional); one without it is invalid. + @Test("include and redefine require a schemaLocation") + func test_includeRedefineRequireSchemaLocation() { + #expect(rejects(#""#)) + #expect(rejects(#""#)) + } + /// A local element declaration must identify itself with a name or a ref; an /// element with neither is invalid, while a named one is valid. @Test("a local element must have a name or a ref") diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift index db4ac86..26f9be8 100644 --- a/Tests/XSTSSuiteTests.swift +++ b/Tests/XSTSSuiteTests.swift @@ -141,20 +141,14 @@ struct XSTSSuiteTests { /// gap) is accepted, 132 → 133. Per the production standard over-rejection is the /// non-starter and under-rejection is recoverable; this debt is recovered by the /// full effective-total-range Particle-Valid-Restriction (tracked). - /// Further rules (each with valid-schemas-rejected held at 0; see CHANGELOG for - /// detail) drove invalid-schemas-accepted 130 -> 79: model-group occurrence ranges - /// (p-props-correct.1, cos-all-limited.2), identity-constraint content model, - /// derivation base-type kind (src-ct.1/.2), element value-constraint content type - /// (cos-valid-default), attribute type must be simple (au-props-correct), resolved - /// schemaLocation must be a schema (src-resolve), import namespace matches the - /// imported target (src-import.3), redefined type derives from itself - /// (src-redefine.5), local complexType is anonymous, a local element has a name - /// or ref, a redefined group's self-reference occurs exactly once - /// (src-redefine.6.1), an identity-constraint xpath uses no undeclared namespace - /// prefix, a redefined group/attributeGroup has at most one self-reference, and a - /// redefined schema's targetNamespace matches the redefiner or is chameleon. + /// Further rules, each with valid-schemas-rejected held at 0 (see CHANGELOG and + /// docs/xsts-deviations.md), drove invalid-schemas-accepted 130 -> 69: model-group + /// occurrence, identity-constraint content model and xpath prefixes, derivation + /// base-type kind and value-constraint content type, attribute/simple-type rules, + /// and the cross-document composition family (src-resolve, src-import.3, + /// src-redefine.5/6.1/7.2.1, redefine cross-namespace, required schemaLocation). private let knownSchemaValidRejected = 0 - private let knownSchemaInvalidAccepted = 71 + private let knownSchemaInvalidAccepted = 69 private let knownInstanceValidRejected = 0 private let knownInstanceInvalidAccepted = 133