fix(schema): include and redefine require a schemaLocation; invalid-schemas-accepted 71 to 69 (#145)

xs:include and xs:redefine require a schemaLocation attribute (only xs:import's
is optional, being a resolution hint). An include or redefine declared without
it is now rejected in the structure walk.

A required-attribute check with no name resolution or reference walking; it
cannot over-reject (schemaLocation is mandatory on these per the
schema-for-schemas), so the full critic loop is not needed here -- reserved for
the false-positive-prone resolution rules. XSTS: invalid-schemas-accepted 71 to
69 (schB3 and a sibling), valid-schemas-rejected held at 0, no other bucket moved.
This commit is contained in:
Mihaela Mihaljevic 2026-06-18 01:33:00 +02:00
parent 7a033d28e6
commit 0994f5dd2a
4 changed files with 20 additions and 15 deletions

View File

@ -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.

View File

@ -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)
}

View File

@ -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(#"<xs:include/>"#))
#expect(rejects(#"<xs:redefine/>"#))
}
/// 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")

View File

@ -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