diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee4299f..fa1ae2d 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): a local `element` declaration must identify itself with a `name` or a `ref`; an element with neither is rejected. invalid-schemas-accepted 80 → 79, no false positive (valid-schemas-rejected held at 0), no other bucket moved.
+
- 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.
diff --git a/Sources/Schema/SchemaAttributeApplicability.swift b/Sources/Schema/SchemaAttributeApplicability.swift
index 79b4e10..95773ab 100644
--- a/Sources/Schema/SchemaAttributeApplicability.swift
+++ b/Sources/Schema/SchemaAttributeApplicability.swift
@@ -169,6 +169,9 @@ extension PureXML.Schema.XSDParser {
PureXML.Schema.XSDNode.localName(parent) != "schema"
else { return [] }
var errors: [String] = []
+ if PureXML.Schema.XSDNode.attribute(node, "name") == nil, PureXML.Schema.XSDNode.attribute(node, "ref") == nil {
+ errors.append("a local element declaration must have a 'name' or a 'ref'")
+ }
for forbidden in ["abstract", "final", "substitutionGroup"] where hasUnprefixed(node, forbidden) {
errors.append("a local element declaration may not specify '\(forbidden)'")
}
diff --git a/Tests/SchemaStructureTests.swift b/Tests/SchemaStructureTests.swift
index cad3088..a3a65c4 100644
--- a/Tests/SchemaStructureTests.swift
+++ b/Tests/SchemaStructureTests.swift
@@ -372,23 +372,21 @@ struct SchemaStructureOrderTests {
"""#))
}
+ /// 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")
+ func test_localElementNameOrRef() {
+ #expect(rejects(#""#))
+ #expect(!rejects(#""#))
+ }
+
/// 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(#"""
-
-
-
-
-
- """#))
- // A top-level named complexType, and an anonymous local one, are both valid.
+ #expect(rejects(#""#))
+ // A named top-level complexType and an anonymous local one are both valid.
try? compile(#""#)
- #expect(!rejects(#"""
-
-
-
- """#))
+ #expect(!rejects(#""#))
}
}
diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift
index 6d5f451..6c5f55a 100644
--- a/Tests/XSTSSuiteTests.swift
+++ b/Tests/XSTSSuiteTests.swift
@@ -141,20 +141,17 @@ 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).
- /// Six further rules, each with valid-schemas-rejected held at 0 (see CHANGELOG
- /// for detail): model-group occurrence ranges (p-props-correct.1, cos-all-limited.2)
- /// 130->110; identity-constraint content model 110->104; derivation base-type kind
- /// (src-ct.1/.2, local type beats the built-in reading) 104->99; element value
- /// constraint needs simple/mixed content (cos-valid-default) 99->96; an attribute's
- /// type is a simple type (au-props-correct) 96->95; a resolved include/import/
- /// redefine schemaLocation must be a well-formed schema (src-resolve) 95->87; and
- /// 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; and a complexType nested in an element must be anonymous (no name)
- /// 81->80.
+ /// 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, and a local element has a
+ /// name or ref.
private let knownSchemaValidRejected = 0
- private let knownSchemaInvalidAccepted = 80
+ private let knownSchemaInvalidAccepted = 79
private let knownInstanceValidRejected = 0
private let knownInstanceInvalidAccepted = 133