fix(schema): reject a redefine that redefines a component twice (#145)
A redefine may redefine a given component at most once (src-redefine.7.2.2); two redefinitions of the same kind and name in one redefine are invalid. XSTS invalid-schemas-accepted 182 to 181, no other bucket moved.
This commit is contained in:
parent
4551508dd9
commit
97817ab611
@ -22,7 +22,7 @@ Second pre-release. Continues the W3C XSTS schema-validity campaign: **invalid-s
|
||||
|
||||
### Fixed
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a `redefine` is now checked against the schema it redefines once that schema is loaded: every component the `redefine` names (a `complexType`, `simpleType`, `group`, or `attributeGroup`) must have a same-kind component of the same name in the redefined schema (`src-redefine.6`/`7.2.1`). A redefinition naming a component that does not exist there is rejected. The check runs only when the redefined document was loaded through a `schemaLoader`, so a stand-alone schema is unaffected. Caught one invalid schema: invalid-schemas-accepted 183 → 182, no other bucket moved.
|
||||
- XSTS invalid-schemas-accepted (#145): a `redefine` is now checked against the schema it redefines once that schema is loaded: every component the `redefine` names (a `complexType`, `simpleType`, `group`, or `attributeGroup`) must have a same-kind component of the same name in the redefined schema (`src-redefine.6`/`7.2.1`), and the same component may not be redefined twice in one `redefine` (`src-redefine.7.2.2`). A redefinition naming a component that does not exist there, or a duplicate redefinition, is rejected. The check runs only when the redefined document was loaded through a `schemaLoader`, so a stand-alone schema is unaffected. Caught two invalid schemas: invalid-schemas-accepted 183 → 181, no other bucket moved.
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): an element or attribute `default`/`fixed` value constraint is now validated against an inline type (an inline `simpleType`, or an inline complex type with `simpleContent`) just as it already was against a named `type` reference, so a non-numeric `default` on a decimal-based inline type is rejected. Validated against the simpleContent base's value space, so only a clear value-space mismatch is flagged. Caught two invalid schemas: invalid-schemas-accepted 185 → 183, no other bucket moved.
|
||||
|
||||
|
||||
@ -101,12 +101,13 @@ extension PureXML.Schema.XSDParser {
|
||||
return xsdErrors + simpleContentErrors + errors + redefineComponentExistenceErrors(containers)
|
||||
}
|
||||
|
||||
/// XSD 1.0 `src-redefine.6.1.1`/`6.2.1`/`7.2.1`: each component a `redefine`
|
||||
/// names must have a same-kind component of that name in the redefined schema.
|
||||
/// Runs only past the cross-document skip guard above, so the redefined schema
|
||||
/// is loaded; a redefinition whose name matches nothing in any non-`redefine`
|
||||
/// container (the loaded targets and the root) names a component that does not
|
||||
/// exist and is invalid.
|
||||
/// XSD 1.0 `src-redefine.6`/`7.2.1`/`7.2.2`: each component a `redefine` names
|
||||
/// must have a same-kind component of that name in the redefined schema, and a
|
||||
/// `redefine` may redefine a given component at most once. Runs only past the
|
||||
/// cross-document skip guard above, so the redefined schema is loaded; a
|
||||
/// redefinition whose name matches nothing in any non-`redefine` container (the
|
||||
/// loaded targets and the root) names a component that does not exist, and a
|
||||
/// name redefined twice in one `redefine` is a duplicate redefinition.
|
||||
private static func redefineComponentExistenceErrors(_ containers: [XSDTree]) -> [String] {
|
||||
let kinds = ["complexType", "simpleType", "group", "attributeGroup"]
|
||||
var defined: [String: Set<String>] = [:]
|
||||
@ -121,10 +122,13 @@ extension PureXML.Schema.XSDParser {
|
||||
}
|
||||
var errors: [String] = []
|
||||
for container in containers where PureXML.Schema.XSDNode.localName(container) == "redefine" {
|
||||
var redefinedHere: [String: Set<String>] = [:]
|
||||
for kind in kinds {
|
||||
for node in PureXML.Schema.XSDNode.children(container, named: kind) {
|
||||
guard let name = PureXML.Schema.XSDNode.attribute(node, "name") else { continue }
|
||||
if defined[kind]?.contains(name) != true {
|
||||
if !redefinedHere[kind, default: []].insert(name).inserted {
|
||||
errors.append("a redefine redefines \(kind) '\(name)' more than once")
|
||||
} else if defined[kind]?.contains(name) != true {
|
||||
errors.append("a redefine of \(kind) '\(name)' has no '\(name)' to redefine in the redefined schema")
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,11 +73,9 @@ struct XSTSSuiteTests {
|
||||
/// `{37,17}`) as schema-invalid, while staying lenient on constructs the
|
||||
/// engine merely does not support, then caught eighteen invalid schemas:
|
||||
/// invalid-schemas-accepted 262 → 244, no other bucket moved.
|
||||
/// Two schema-for-schemas structural rules then caught nine more invalid
|
||||
/// schemas: a named group's compositor may not carry minOccurs/maxOccurs (those
|
||||
/// belong on a reference), and an attribute in the XML Schema namespace (e.g.
|
||||
/// `xsd:type`) is never valid. Invalid-schemas accepted 244 → 235, no other
|
||||
/// bucket moved.
|
||||
/// Two schema-for-schemas structural rules (a named group's compositor may not
|
||||
/// carry minOccurs/maxOccurs; an attribute in the XML Schema namespace is never
|
||||
/// valid) then caught nine more: invalid-schemas accepted 244 → 235.
|
||||
/// Rejecting a complexContent extension that adds element content (a model
|
||||
/// group) on top of a simpleContent base (cos-ct-extends.1.4.2.2) then caught
|
||||
/// two more invalid schemas; an attribute-only complexContent extension of a
|
||||
@ -152,8 +150,11 @@ struct XSTSSuiteTests {
|
||||
/// the redefined schema once that schema is loaded (src-redefine.6/7.2.1) then
|
||||
/// caught one more invalid schema: invalid-schemas accepted 183 → 182, no other
|
||||
/// bucket moved.
|
||||
/// Rejecting a `redefine` that redefines the same component twice (src-redefine.7.2.2)
|
||||
/// then caught one more invalid schema: invalid-schemas accepted 182 → 181, no
|
||||
/// other bucket moved.
|
||||
private let knownSchemaValidRejected = 1
|
||||
private let knownSchemaInvalidAccepted = 182
|
||||
private let knownSchemaInvalidAccepted = 181
|
||||
private let knownInstanceValidRejected = 3
|
||||
private let knownInstanceInvalidAccepted = 132
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user