fix(schema): require complexContent extension mixed to agree with its base (#145)
A complexContent extension that explicitly states mixed must match its base type's mixedness (cos-ct-extends.1.4.3.2.2.1): a mixed extension extends only a mixed base, an element-only extension only an element-only base. An extension that omits mixed inherits the base's setting and stays valid, so only an explicit conflict is rejected (ctZ012b, which inherits, is not flagged). XSTS invalid-schemas-accepted 197 to 194, no other bucket moved.
This commit is contained in:
parent
b0479fd329
commit
fd97faf291
@ -22,6 +22,8 @@ Second pre-release. Continues the W3C XSTS schema-validity campaign: **invalid-s
|
||||
|
||||
### Fixed
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `complexContent` extension that explicitly states `mixed` must agree with its base type's mixedness (`cos-ct-extends.1.4.3.2.2.1`): a mixed extension may extend only a mixed base, and an element-only extension only an element-only base. An extension that omits `mixed` inherits the base's setting and stays valid, so only an explicit conflict is rejected. Caught three invalid schemas: invalid-schemas-accepted 197 → 194, no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `complexContent` or `simpleContent` must contain exactly one `restriction` or `extension`. An empty `<complexContent/>` (or `<simpleContent/>`), which declares no derivation, is now rejected as a structural error. Caught three invalid schemas: invalid-schemas-accepted 200 → 197, no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `pattern` facet whose `\p{...}` or `\P{...}` property name can be no XSD `charProp` (`IsCategory | IsBlock`) under any repertoire is now rejected as a schema-validity error: an empty name, the bare prefix `Is`, a non-block name carrying a non-letter (`\p{\L}`), or `Is` followed by a non-block character. A well-formed but unrecognised category or block name (such as an unknown `Is`-block) stays a lenient engine limitation rather than an error, so only the unambiguously malformed forms reject. Caught three invalid schemas: invalid-schemas-accepted 203 → 200, no other bucket moved.
|
||||
|
||||
@ -342,10 +342,11 @@ extension PureXML.Validation.SchemaCompile {
|
||||
/// cos-ct-extends.1.4.2.2: a complexContent extension adding element content
|
||||
/// must have a base with complex (or empty) content, not simpleContent.
|
||||
static var complexExtensionBaseValid: PureXML.Validation.Validation<PureXML.Schema.SchemaCompileRoot, PureXML.Schema.SchemaCompileContext> {
|
||||
compileRule("A complexContent extension's base has complex content") { document in
|
||||
compileRule("A complexContent extension is consistent with its base type") { document in
|
||||
guard let namedTypes = document.namedTypes else { return [] }
|
||||
return PureXML.Schema.SchemaLocatedFinding.unlocated(
|
||||
PureXML.Schema.XSDParser.simpleContentExtensionBaseErrors(document.schema, document.context, namedTypes),
|
||||
PureXML.Schema.XSDParser.simpleContentExtensionBaseErrors(document.schema, document.context, namedTypes)
|
||||
+ PureXML.Schema.XSDParser.extensionMixedAgreementErrors(document.schema, document.context, namedTypes),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,6 +76,48 @@ extension PureXML.Schema.XSDParser {
|
||||
return errors
|
||||
}
|
||||
|
||||
/// XSD 1.0 `cos-ct-extends.1.4.3.2.2.1`: a `complexContent` extension's mixedness
|
||||
/// must match its base type's. The effective content joins the base content and
|
||||
/// the extension's, so a mixed extension may extend only a mixed base and an
|
||||
/// element-only extension only an element-only base. Checked for a self-contained
|
||||
/// schema, and only when the base content is definitely element-only or mixed (an
|
||||
/// empty or simple-content base is governed by other rules and is left alone).
|
||||
static func extensionMixedAgreementErrors(_ schema: XSDTree, _ context: PureXML.Schema.XSDContext, _ types: [String: PureXML.Schema.ElementType]) -> [String] {
|
||||
guard !skipsCrossDocumentRules(schema, compositionLoaded: context.compositionLoaded) else { return [] }
|
||||
let bindings = context.namespaceBindings
|
||||
var errors: [String] = []
|
||||
for content in descendants(schema, named: "complexContent") {
|
||||
guard let ext = ExtAllNode.firstChild(content, named: "extension"),
|
||||
let base = ExtAllNode.attribute(ext, "base"),
|
||||
ExtAllNode.referenceNamespace(base, bindings) == context.targetNamespace,
|
||||
case let .complex(complex)? = types[ExtAllNode.stripPrefix(base)]
|
||||
else { continue }
|
||||
let baseIsMixed: Bool
|
||||
switch complex.content {
|
||||
case .mixed: baseIsMixed = true
|
||||
case .elementOnly: baseIsMixed = false
|
||||
case .empty, .simpleContent: continue
|
||||
}
|
||||
// An extension that does not state `mixed` inherits the base's, so there
|
||||
// is no conflict; only an EXPLICIT `mixed` that disagrees is invalid.
|
||||
guard let derivedMixed = explicitMixed(content) else { continue }
|
||||
if baseIsMixed != derivedMixed {
|
||||
errors.append("a complexContent extension of '\(ExtAllNode.stripPrefix(base))' must have the same mixed setting as its base")
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
/// The EXPLICIT `mixed` of a `complexContent` derivation: its own `mixed`
|
||||
/// attribute when present, otherwise the enclosing `complexType`'s, or nil when
|
||||
/// neither states it (an extension then inherits its base's mixedness). `true`
|
||||
/// and `1` are mixed.
|
||||
private static func explicitMixed(_ complexContent: XSDTree) -> Bool? {
|
||||
if let own = ExtAllNode.attribute(complexContent, "mixed") { return own == "true" || own == "1" }
|
||||
if let parent = complexContent.parent, let outer = ExtAllNode.attribute(parent, "mixed") { return outer == "true" || outer == "1" }
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Whether a `complexContent` extension adds element content: an `element` or
|
||||
/// a wildcard `any` somewhere in its model group. An empty group (`<sequence/>`)
|
||||
/// or an attribute-only extension adds no element content, so it keeps the
|
||||
|
||||
@ -100,7 +100,7 @@ struct ValidationConfigurationTests {
|
||||
"ID-typed value constraints are valid",
|
||||
"Element value constraints are valid against their declared types",
|
||||
"Complex types extending xs:all groups satisfy XSD placement rules",
|
||||
"A complexContent extension's base has complex content",
|
||||
"A complexContent extension is consistent with its base type",
|
||||
"Attribute restrictions are faithful to their bases",
|
||||
"Simple types do not derive from complex types",
|
||||
"Simple-type varieties are declared consistently",
|
||||
|
||||
@ -129,8 +129,13 @@ struct XSTSSuiteTests {
|
||||
/// `restriction` or `extension` (an empty `<complexContent/>` has none) then
|
||||
/// caught three more invalid schemas: invalid-schemas accepted 200 → 197, no
|
||||
/// other bucket moved.
|
||||
/// Requiring a `complexContent` extension that explicitly states `mixed` to agree
|
||||
/// with its base's mixedness (cos-ct-extends.1.4.3.2.2.1; an extension that omits
|
||||
/// `mixed` inherits the base's, so only an explicit conflict is invalid) then
|
||||
/// caught three more invalid schemas: invalid-schemas accepted 197 → 194, no
|
||||
/// other bucket moved.
|
||||
private let knownSchemaValidRejected = 1
|
||||
private let knownSchemaInvalidAccepted = 197
|
||||
private let knownSchemaInvalidAccepted = 194
|
||||
private let knownInstanceValidRejected = 3
|
||||
private let knownInstanceInvalidAccepted = 132
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user