diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95b48ba..fdc505f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
-- XSTS invalid-schemas-accepted (#145, #161): a redefinition of an attribute group restricts the original, so it may neither eliminate a required attribute the original declares nor re-introduce a prohibited one as usable (src-redefine / cos-ct-restricts). attgZ002 (dropping the required `att1`) and attgZ003 (re-adding the prohibited `att1` as optional) are now rejected. Re-declaring a prohibited attribute AS prohibited keeps it prohibited and stays valid, and the drop-required check is skipped when the redefinition uses a nested attributeGroup reference (which could re-introduce the attribute), so no valid redefinition is rejected. invalid-schemas-accepted 67 → 65, no false positive (valid-schemas-rejected and valid-instances-rejected held at 0), no other bucket moved.
+- XSTS invalid-schemas-accepted (#145, #161): a redefinition of an attribute group restricts the original, so it may neither eliminate a required attribute the original declares, nor re-introduce a prohibited one as usable, nor relax a fixed value the original sets (src-redefine / cos-ct-restricts). attgZ002 (dropping the required `att1`), attgZ003 (re-adding the prohibited `att1` as optional), and schM10 (changing a `fixed` attribute to a `default` one) are now rejected. Re-declaring a prohibited attribute AS prohibited keeps it prohibited and stays valid, the drop-required check is skipped when the redefinition uses a nested attributeGroup reference (which could re-introduce the attribute), and the fixed-value check fires only when the redefinition declares the matching attribute as non-prohibited with a differing fixed value (keeping the same fixed value, prohibiting it, or omitting it is left alone), so no valid redefinition is rejected. invalid-schemas-accepted 67 → 64, no false positive (valid-schemas-rejected and valid-instances-rejected held at 0), no other bucket moved.
- A complex type whose `simpleContent` derives from a list or union simple type now keeps that variety, so its element content is validated as a list or union rather than collapsing to an atomic value space. Previously `simpleContentType` dropped the base's variety, so an invalid item in a list-typed simpleContent (e.g. a non-int in a list-of-int) was accepted. A valid list/union value is unaffected. (Under-rejection fix surfaced by the libxml2 differential; the W3C suite does not exercise it, so the conformance counts are unchanged.)
diff --git a/Sources/Schema/SchemaRedefineSelfReference.swift b/Sources/Schema/SchemaRedefineSelfReference.swift
index 0585dcf..cfa0871 100644
--- a/Sources/Schema/SchemaRedefineSelfReference.swift
+++ b/Sources/Schema/SchemaRedefineSelfReference.swift
@@ -90,23 +90,28 @@ extension PureXML.Schema.XSDParser {
private static func attributeGroupRestrictionErrors(name: String, base: XSDTree, redefinition: XSDTree) -> [String] {
var errors: [String] = []
let children = RedefineNode.elementChildren(redefinition)
- // The redefinition's attributes by name -> `use`; re-declaring a base
- // prohibited attribute AS prohibited keeps it prohibited (valid), so the
- // re-introduction check needs the use, not mere presence of the name.
- var redefinedUse: [String: String] = [:]
+ // The redefinition's attributes by name, so a check can read the `use` (a
+ // re-declared prohibited attribute kept prohibited is valid) and the `fixed`
+ // value (a restriction may not relax the original's fixed constraint).
+ var redefined: [String: XSDTree] = [:]
for attribute in children where RedefineNode.localName(attribute) == "attribute" {
- if let attrName = RedefineNode.attribute(attribute, "name") {
- redefinedUse[attrName] = RedefineNode.attribute(attribute, "use") ?? "optional"
- }
+ if let attrName = RedefineNode.attribute(attribute, "name") { redefined[attrName] = attribute }
}
+ let use: (String) -> String? = { redefined[$0].map { RedefineNode.attribute($0, "use") ?? "optional" } }
let hasReference = children.contains { RedefineNode.localName($0) == "attributeGroup" }
let baseHasWildcard = RedefineNode.elementChildren(base).contains { RedefineNode.localName($0) == "anyAttribute" }
for attribute in RedefineNode.children(base, named: "attribute") {
guard let attrName = RedefineNode.attribute(attribute, "name") else { continue }
+ // A restriction may not relax a fixed value: if the original fixes an
+ // attribute, the redefinition's matching (non-prohibited) attribute must
+ // fix it to the same value.
+ if relaxesFixedValue(base: attribute, redefined: redefined[attrName], use: use(attrName)) {
+ errors.append("a redefined attribute group '\(name)' may not relax the fixed value of '\(attrName)'")
+ }
switch RedefineNode.attribute(attribute, "use") {
- case "required" where !hasReference && redefinedUse[attrName] == nil:
+ case "required" where !hasReference && redefined[attrName] == nil:
errors.append("a redefined attribute group '\(name)' may not eliminate the required attribute '\(attrName)'")
- case "prohibited" where !baseHasWildcard && redefinedUse[attrName] != nil && redefinedUse[attrName] != "prohibited":
+ case "prohibited" where !baseHasWildcard && use(attrName) != nil && use(attrName) != "prohibited":
errors.append("a redefined attribute group '\(name)' may not re-introduce the prohibited attribute '\(attrName)'")
default:
break
@@ -115,6 +120,14 @@ extension PureXML.Schema.XSDParser {
return errors
}
+ /// A base attribute with a `fixed` value is relaxed when the redefinition declares
+ /// a matching, non-prohibited attribute whose `fixed` value differs (or is absent).
+ /// Prohibiting or omitting the attribute is not relaxation, so it is left alone.
+ private static func relaxesFixedValue(base: XSDTree, redefined: XSDTree?, use: String?) -> Bool {
+ guard let fixed = RedefineNode.attribute(base, "fixed"), let redefined, use != "prohibited" else { return false }
+ return RedefineNode.attribute(redefined, "fixed") != fixed
+ }
+
/// The reference NODES of `kind` nested directly in `node`'s model, stopping at
/// `element`/`complexType`/`simpleType`/`attribute` scopes so a reference inside a
/// nested element's content (a data-structure recursion, not a redefinition
diff --git a/Tests/SchemaRedefineAttributeGroupTests.swift b/Tests/SchemaRedefineAttributeGroupTests.swift
index 498d08e..a5e72b0 100644
--- a/Tests/SchemaRedefineAttributeGroupTests.swift
+++ b/Tests/SchemaRedefineAttributeGroupTests.swift
@@ -43,4 +43,22 @@ struct SchemaRedefineAttributeGroupTests {
base: "",
)
}
+
+ @Test("relaxing a fixed value in the redefinition is rejected")
+ func test_relaxFixedRejected() throws {
+ #expect(throws: (any Error).self) {
+ try redefine(
+ group: "",
+ base: "",
+ )
+ }
+ }
+
+ @Test("keeping the same fixed value in the redefinition is valid")
+ func test_keepFixedAccepted() throws {
+ _ = try redefine(
+ group: "",
+ base: "",
+ )
+ }
}
diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift
index 99ff859..4b8cb24 100644
--- a/Tests/XSTSSuiteTests.swift
+++ b/Tests/XSTSSuiteTests.swift
@@ -148,7 +148,7 @@ struct XSTSSuiteTests {
/// 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 = 65
+ private let knownSchemaInvalidAccepted = 64
private let knownInstanceValidRejected = 0
/// Instance bucket (133 -> 31), per-step deltas in CHANGELOG.md: xsi:type must derive from the
/// declared type (complex, then atomic and list/union, resolved through the element-ref chain);