diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b03520..2b9f446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ Second pre-release. Continues the W3C XSTS schema-validity campaign: **invalid-s ### Fixed +- XSTS invalid-schemas-accepted (#145): two attribute-declaration validity rules. An attribute `ref` may not also carry `form` (the form comes from the referenced global declaration; `src-attribute.3.2`), and no attribute declaration may be named `xmlns` (that name is reserved for namespace declarations; no-xmlns). Caught four invalid schemas: invalid-schemas-accepted 207 → 203, no other bucket moved. + - XSTS invalid-schemas-accepted (#145): a referencing `attributeGroup` (one carrying a `ref`) is held to its `(annotation?)` content model. It names a definition elsewhere, so it may not itself declare attributes, nested attributeGroup references, or an `anyAttribute`; only a defining `attributeGroup` (with `name`) carries those (`attgD`). Caught three invalid schemas: invalid-schemas-accepted 210 → 207, no other bucket moved. - XSTS invalid-schemas-accepted (#145): notation names are now part of the component-name uniqueness check. A notation has its own symbol space, so two notations sharing a name and target namespace are a duplicate just as two global types or elements would be (`notatB005`). Caught one invalid schema: invalid-schemas-accepted 211 → 210, no other bucket moved. diff --git a/Sources/Schema/SchemaAttributeApplicability.swift b/Sources/Schema/SchemaAttributeApplicability.swift index da62c31..f313da7 100644 --- a/Sources/Schema/SchemaAttributeApplicability.swift +++ b/Sources/Schema/SchemaAttributeApplicability.swift @@ -62,6 +62,16 @@ extension PureXML.Schema.XSDParser { errors.append("attribute '\(name)' is not allowed on '\(local)'") } } + return errors + refAndNameExclusionErrors(node, local: local, present: present) + } + + /// The exclusions a `ref`, a `type`, or a reserved name impose on an element or + /// attribute, beyond the per-component allowed-attribute table: `ref` excludes + /// `name`/`type` (and, on an element, the other declaration-only properties; on + /// an attribute, `form`) and an inline type; a `type` excludes an inline type; + /// and an attribute may not be named `xmlns` (no-xmlns). + private static func refAndNameExclusionErrors(_ node: XSDTree, local: String, present: Set) -> [String] { + var errors: [String] = [] if present.contains("ref"), present.contains("name") { errors.append("'\(local)' may not have both 'ref' and 'name'") } @@ -77,6 +87,17 @@ extension PureXML.Schema.XSDParser { errors.append("'element' with a 'ref' may not also specify '\(excluded)'") } } + // src-attribute.3.2: an attribute `ref` is a use of a global declaration, so + // beyond name/type it may not carry `form` either (the form comes from the + // referenced declaration). `use` and a value constraint stay allowed on the use. + if local == "attribute", present.contains("ref"), present.contains("form") { + errors.append("'attribute' with a 'ref' may not also specify 'form'") + } + // no-xmlns: the {name} of an attribute declaration may not match `xmlns` + // (that name is reserved for namespace declarations). + if local == "attribute", PureXML.Schema.XSDNode.attribute(node, "name") == "xmlns" { + errors.append("an attribute declaration may not be named 'xmlns'") + } // A `ref` likewise excludes an inline type definition: the type comes from the // referenced declaration. if present.contains("ref"), local == "element" || local == "attribute", hasInlineType(node, local) { diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift index a52dc2d..2197c34 100644 --- a/Tests/XSTSSuiteTests.swift +++ b/Tests/XSTSSuiteTests.swift @@ -117,8 +117,11 @@ struct XSTSSuiteTests { /// content model, so it may not also declare attributes, nested attributeGroup /// references, or an anyAttribute, then caught three more invalid schemas: /// invalid-schemas accepted 210 → 207, no other bucket moved. + /// Rejecting an attribute `ref` that also carries `form` (src-attribute.3.2) and + /// an attribute declaration named `xmlns` (no-xmlns) then caught four more + /// invalid schemas: invalid-schemas accepted 207 → 203, no other bucket moved. private let knownSchemaValidRejected = 1 - private let knownSchemaInvalidAccepted = 207 + private let knownSchemaInvalidAccepted = 203 private let knownInstanceValidRejected = 3 private let knownInstanceInvalidAccepted = 132