fix(schema): enforce simpleType restriction structure and QName prefix bindings
This commit is contained in:
parent
1dcff00874
commit
ffff13da57
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- Enforce simpleType restriction structure and prefix binding constraints (XSD 1.0 Datatypes §3.2.1 / Structures §3.3.1 / §3.14.3). Verify that restriction under simpleType only admits annotation, simpleType and facets, disallowing attributes, wildcards, model groups, and multiple or misplaced inline simpleTypes. Reject a restriction base, list itemType, or union memberType resolving to a complex type (e.g. anyType). Enforce that all QName attributes have bound prefixes. XSTS: invalid schemas accepted 350 to 333, no other bucket raised.
|
||||
- A top-level group or attributeGroup definition may no longer carry local-use attributes (XSD 1.0 Structures §3.6.1 / §3.6.2). A global group definition (including one defined inside `xs:redefine`) must only have name and id attributes, and local-use attributes like `ref`, `minOccurs`, or `maxOccurs` are rejected; a global attributeGroup definition may not carry a `ref` attribute. XSTS: invalid schemas accepted 354 to 350, no other bucket raised.
|
||||
- Support attribute inheritance and prohibition in complexContent restriction derivations (XSD 1.0 Structures §3.4.6 / Schema Component Constraint: Derivation Valid (Restriction, Complex)). When a complexType restricts a base type, the restricted type inherits all base attributes that are not explicitly overridden or prohibited by the restriction. A prohibited attribute is excluded from the final type's attributes, preventing its use in instance validation. Resolves referenced attributes namespace-aware using prefix bindings. XSTS: valid instances rejected 180 to 171, invalid instances accepted 158 to 155, no other bucket raised.
|
||||
- A complexContent restriction must keep a base attribute's required use and its fixed value constraint (XSD 1.0 `cos-ct-derived-ok` / `derivation-ok-restriction.2` / `derivation-ok-restriction.4`). A restriction redeclaring a base `required` attribute may not make it optional or prohibited, and if a base attribute use has a `fixed` value constraint, the restriction must also make it `fixed` with the same value. The fixed values are compared in the attribute type's value space (supporting lists and unions) to avoid over-rejecting valid schemas. A prohibited attribute is removed, so the fixed clause does not apply to it. XSTS: invalid schemas accepted 390 to 387, no other bucket raised.
|
||||
|
||||
@ -73,5 +73,6 @@ extension PureXML.Schema.XSDParser {
|
||||
+ userTypeValueConstraintErrors(schema, context, typeMaps.named)
|
||||
+ extensionAllGroupErrors(schema, context, typeMaps.named)
|
||||
+ attributeRestrictionErrors(schema, context, typeMaps.named)
|
||||
+ simpleTypeBaseNotComplexErrors(schema, in: context)
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,4 +100,69 @@ extension PureXML.Schema.XSDParser {
|
||||
private static func localName(_ qname: String) -> String {
|
||||
PureXML.Schema.XSDNode.stripPrefix(qname.trimmingXMLWhitespace())
|
||||
}
|
||||
|
||||
static func simpleTypeBaseNotComplexErrors(_ schema: XSDTree, in context: PureXML.Schema.XSDContext) -> [String] {
|
||||
var errors: [String] = []
|
||||
let bindings = PureXML.Schema.XSDNode.namespaceBindings(of: schema)
|
||||
let targetNamespace = context.targetNamespace
|
||||
|
||||
func isComplex(_ qname: String) -> Bool {
|
||||
let trimmed = qname.trimmingXMLWhitespace()
|
||||
let prefix = PureXML.Schema.XSDNode.prefix(trimmed)
|
||||
let uri = prefix.flatMap { bindings[$0] } ?? bindings[""]
|
||||
let local = PureXML.Schema.XSDNode.stripPrefix(trimmed)
|
||||
if uri == xsdNamespace {
|
||||
return local == "anyType"
|
||||
}
|
||||
if uri == targetNamespace || uri == nil || uri == "" {
|
||||
return context.complexTypeNodes[local] != nil
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func check(_ node: XSDTree) {
|
||||
let local = PureXML.Schema.XSDNode.localName(node)
|
||||
if local == "appinfo" || local == "documentation" { return }
|
||||
|
||||
if node.name?.namespaceURI == xsdNamespace {
|
||||
switch local {
|
||||
case "restriction":
|
||||
Self.checkRestrictionUnderSimpleType(node, isComplex: isComplex, errors: &errors)
|
||||
case "list":
|
||||
Self.checkList(node, isComplex: isComplex, errors: &errors)
|
||||
case "union":
|
||||
Self.checkUnion(node, isComplex: isComplex, errors: &errors)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for child in PureXML.Schema.XSDNode.elementChildren(node) {
|
||||
check(child)
|
||||
}
|
||||
}
|
||||
check(schema)
|
||||
return errors
|
||||
}
|
||||
|
||||
private static func checkRestrictionUnderSimpleType(_ node: XSDTree, isComplex: (String) -> Bool, errors: inout [String]) {
|
||||
guard let parent = node.parent, parent.name?.namespaceURI == xsdNamespace, PureXML.Schema.XSDNode.localName(parent) == "simpleType" else { return }
|
||||
if let base = PureXML.Schema.XSDNode.attribute(node, "base"), isComplex(base) {
|
||||
errors.append("base type '\(base)' of simpleType restriction must be a simple type, not a complex type")
|
||||
}
|
||||
}
|
||||
|
||||
private static func checkList(_ node: XSDTree, isComplex: (String) -> Bool, errors: inout [String]) {
|
||||
if let itemType = PureXML.Schema.XSDNode.attribute(node, "itemType"), isComplex(itemType) {
|
||||
errors.append("itemType '\(itemType)' of list must be a simple type, not a complex type")
|
||||
}
|
||||
}
|
||||
|
||||
private static func checkUnion(_ node: XSDTree, isComplex: (String) -> Bool, errors: inout [String]) {
|
||||
if let members = PureXML.Schema.XSDNode.attribute(node, "memberTypes") {
|
||||
for token in members.split(whereSeparator: \.isWhitespace) where isComplex(String(token)) {
|
||||
errors.append("memberType '\(token)' of union must be a simple type, not a complex type")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,8 @@ extension PureXML.Schema.XSDParser {
|
||||
/// Walks the one document rooted at `schema`, skipping foreign content.
|
||||
static func structureErrors(_ schema: XSDTree) -> [String] {
|
||||
var errors: [String] = []
|
||||
collectStructure(schema, into: &errors)
|
||||
let bindings = PureXML.Schema.XSDNode.namespaceBindings(of: schema)
|
||||
collectStructure(schema, bindings: bindings, into: &errors)
|
||||
errors += simpleTypeVarietyFacetErrors(schema)
|
||||
errors += valueConstraintErrors(schema)
|
||||
errors += topLevelDeclarationErrors(schema)
|
||||
@ -64,19 +65,27 @@ extension PureXML.Schema.XSDParser {
|
||||
return errors
|
||||
}
|
||||
|
||||
private static func collectStructure(_ node: XSDTree, into errors: inout [String]) {
|
||||
private static func collectStructure(_ node: XSDTree, bindings: [String: String], into errors: inout [String]) {
|
||||
let local = PureXML.Schema.XSDNode.localName(node)
|
||||
if local == "appinfo" || local == "documentation" { return }
|
||||
let children = PureXML.Schema.XSDNode.elementChildren(node)
|
||||
var currentBindings = bindings
|
||||
for attribute in node.attributes {
|
||||
if attribute.name.prefix == "xmlns" {
|
||||
currentBindings[attribute.name.localName] = attribute.value
|
||||
} else if attribute.name.prefix == nil, attribute.name.localName == "xmlns" {
|
||||
currentBindings[""] = attribute.value
|
||||
}
|
||||
}
|
||||
if node.name?.namespaceURI == xsdNamespace, let local {
|
||||
errors += attributeValueErrors(node)
|
||||
errors += attributeValueErrors(node, bindings: currentBindings)
|
||||
errors += occurrenceOrderErrors(node)
|
||||
errors += attributeApplicabilityErrors(node, local: local)
|
||||
let names = children.filter { $0.name?.namespaceURI == xsdNamespace }.compactMap(PureXML.Schema.XSDNode.localName)
|
||||
errors += componentSpecificErrors(node, local: local, names: names)
|
||||
}
|
||||
for child in children {
|
||||
collectStructure(child, into: &errors)
|
||||
collectStructure(child, bindings: currentBindings, into: &errors)
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +94,7 @@ extension PureXML.Schema.XSDParser {
|
||||
/// identity-XPath, wildcard-namespace, and consistency rules.
|
||||
private static func componentSpecificErrors(_ node: XSDTree, local: String, names: [String]) -> [String] {
|
||||
var errors: [String] = []
|
||||
if let allowed = allowedChildren[local] {
|
||||
if let allowed = allowedChildren(for: local, node: node) {
|
||||
errors += childErrors(local: local, children: names, allowed: allowed)
|
||||
}
|
||||
errors += derivationControlErrors(node, local: local)
|
||||
@ -103,12 +112,24 @@ extension PureXML.Schema.XSDParser {
|
||||
errors += identityXPathErrors(node, local: local)
|
||||
case "any", "anyAttribute":
|
||||
errors += wildcardNamespaceErrors(node)
|
||||
case "restriction":
|
||||
errors += restrictionErrors(node, names: names)
|
||||
case "list":
|
||||
errors += listErrors(node, names: names)
|
||||
default:
|
||||
break
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
private static func allowedChildren(for local: String, node: XSDTree) -> Set<String>? {
|
||||
guard let allowed = allowedChildren[local] else { return nil }
|
||||
if local == "restriction", let parent = node.parent, parent.name?.namespaceURI == xsdNamespace, PureXML.Schema.XSDNode.localName(parent) == "simpleType" {
|
||||
return simpleTypeRestrictionAllowedChildren
|
||||
}
|
||||
return allowed
|
||||
}
|
||||
|
||||
/// The enumerated value space of the schema-vocabulary attributes that take a
|
||||
/// fixed set of tokens. Each name has one meaning throughout XSD, so checking
|
||||
/// by local name is safe; `minOccurs`/`maxOccurs` are handled numerically.
|
||||
@ -128,9 +149,20 @@ extension PureXML.Schema.XSDParser {
|
||||
/// unknown token, or `minOccurs`/`maxOccurs` that is not a `nonNegativeInteger`
|
||||
/// (`maxOccurs` also admits `unbounded`). A prefixed (foreign) attribute is the
|
||||
/// schema author's own and is not checked.
|
||||
private static func attributeValueErrors(_ node: XSDTree) -> [String] {
|
||||
private static func attributeValueErrors(_ node: XSDTree, bindings: [String: String]) -> [String] {
|
||||
node.attributes.filter { $0.name.prefix == nil }.compactMap { attribute in
|
||||
attributeValueError(attribute.name.localName, attribute.value)
|
||||
let name = attribute.name.localName
|
||||
let value = attribute.value
|
||||
if let err = attributeValueError(name, value) {
|
||||
return err
|
||||
}
|
||||
if qnameAttributes.contains(name) {
|
||||
return checkQNamePrefix(value, bindings: bindings)
|
||||
}
|
||||
if name == "memberTypes" {
|
||||
return checkMemberTypesPrefixes(value, bindings: bindings)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,45 +196,6 @@ extension PureXML.Schema.XSDParser {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `value` is a lexical `nonNegativeInteger` (optional `+`, ASCII
|
||||
/// digits), independent of machine-integer range.
|
||||
private static func isNonNegativeInteger(_ value: String) -> Bool {
|
||||
var digits = Substring(value)
|
||||
if digits.first == "+" { digits = digits.dropFirst() }
|
||||
return !digits.isEmpty && digits.allSatisfy { $0.isASCII && $0.isNumber }
|
||||
}
|
||||
|
||||
/// The finding, if any, for a particle whose `minOccurs` exceeds its
|
||||
/// `maxOccurs`. `unbounded` is never exceeded, and a malformed value is left
|
||||
/// to ``attributeValueError``; the comparison is by canonical magnitude, so it
|
||||
/// holds for occurrence counts beyond a machine integer.
|
||||
private static func occurrenceOrderErrors(_ node: XSDTree) -> [String] {
|
||||
guard let minRaw = PureXML.Schema.XSDNode.attribute(node, "minOccurs"),
|
||||
let maxRaw = PureXML.Schema.XSDNode.attribute(node, "maxOccurs")
|
||||
else { return [] }
|
||||
let minimum = minRaw.trimmingXMLWhitespace()
|
||||
let maximum = maxRaw.trimmingXMLWhitespace()
|
||||
guard maximum != "unbounded", isNonNegativeInteger(minimum), isNonNegativeInteger(maximum),
|
||||
exceeds(minimum, maximum)
|
||||
else { return [] }
|
||||
return ["minOccurs (\(minRaw)) exceeds maxOccurs (\(maxRaw))"]
|
||||
}
|
||||
|
||||
/// Whether nonNegativeInteger lexical `lhs` is strictly greater than `rhs`,
|
||||
/// comparing canonical magnitude (sign and leading zeros stripped) by length
|
||||
/// then lexically, so it is independent of machine-integer range.
|
||||
private static func exceeds(_ lhs: String, _ rhs: String) -> Bool {
|
||||
let left = canonicalMagnitude(lhs), right = canonicalMagnitude(rhs)
|
||||
return left.count != right.count ? left.count > right.count : left > right
|
||||
}
|
||||
|
||||
private static func canonicalMagnitude(_ value: String) -> Substring {
|
||||
var digits = Substring(value)
|
||||
if digits.first == "+" { digits = digits.dropFirst() }
|
||||
let trimmed = digits.drop { $0 == "0" }
|
||||
return trimmed.isEmpty ? "0" : trimmed
|
||||
}
|
||||
|
||||
private static func childErrors(local: String, children: [String], allowed: Set<String>) -> [String] {
|
||||
var errors: [String] = []
|
||||
for name in children where !allowed.contains(name) {
|
||||
|
||||
101
Sources/Schema/SchemaStructureHelpers.swift
Normal file
101
Sources/Schema/SchemaStructureHelpers.swift
Normal file
@ -0,0 +1,101 @@
|
||||
extension PureXML.Schema.XSDParser {
|
||||
static let simpleTypeRestrictionAllowedChildren: Set<String> = {
|
||||
let facets: Set = [
|
||||
"minExclusive", "minInclusive", "maxExclusive", "maxInclusive", "totalDigits",
|
||||
"fractionDigits", "length", "minLength", "maxLength", "enumeration", "whiteSpace", "pattern",
|
||||
]
|
||||
return Set(["annotation", "simpleType"]).union(facets)
|
||||
}()
|
||||
|
||||
static func checkQNamePrefix(_ qname: String, bindings: [String: String]) -> String? {
|
||||
let trimmed = qname.trimmingXMLWhitespace()
|
||||
guard PureXML.Schema.Lexical.isQName(trimmed) else { return nil }
|
||||
if let prefix = PureXML.Schema.XSDNode.prefix(trimmed) {
|
||||
if prefix == "xml" { return nil }
|
||||
if bindings[prefix] == nil {
|
||||
return "prefix '\(prefix)' is not bound"
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
static func checkMemberTypesPrefixes(_ memberTypes: String, bindings: [String: String]) -> String? {
|
||||
let tokens = memberTypes.trimmingXMLWhitespace().split(whereSeparator: \.isWhitespace).map(String.init)
|
||||
for token in tokens {
|
||||
if let err = checkQNamePrefix(token, bindings: bindings) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
static func isNonNegativeInteger(_ value: String) -> Bool {
|
||||
var digits = Substring(value)
|
||||
if digits.first == "+" { digits = digits.dropFirst() }
|
||||
return !digits.isEmpty && digits.allSatisfy { $0.isASCII && $0.isNumber }
|
||||
}
|
||||
|
||||
static func occurrenceOrderErrors(_ node: XSDTree) -> [String] {
|
||||
guard let minRaw = PureXML.Schema.XSDNode.attribute(node, "minOccurs"),
|
||||
let maxRaw = PureXML.Schema.XSDNode.attribute(node, "maxOccurs")
|
||||
else { return [] }
|
||||
let minimum = minRaw.trimmingXMLWhitespace()
|
||||
let maximum = maxRaw.trimmingXMLWhitespace()
|
||||
guard maximum != "unbounded", isNonNegativeInteger(minimum), isNonNegativeInteger(maximum),
|
||||
exceeds(minimum, maximum)
|
||||
else { return [] }
|
||||
return ["minOccurs (\(minRaw)) exceeds maxOccurs (\(maxRaw))"]
|
||||
}
|
||||
|
||||
static func exceeds(_ lhs: String, _ rhs: String) -> Bool {
|
||||
let left = canonicalMagnitude(lhs), right = canonicalMagnitude(rhs)
|
||||
return left.count != right.count ? left.count > right.count : left > right
|
||||
}
|
||||
|
||||
static func canonicalMagnitude(_ value: String) -> Substring {
|
||||
var digits = Substring(value)
|
||||
if digits.first == "+" { digits = digits.dropFirst() }
|
||||
let trimmed = digits.drop { $0 == "0" }
|
||||
return trimmed.isEmpty ? "0" : trimmed
|
||||
}
|
||||
|
||||
static func restrictionErrors(_ node: XSDTree, names: [String]) -> [String] {
|
||||
var errors: [String] = []
|
||||
guard let parent = node.parent, parent.name?.namespaceURI == xsdNamespace, PureXML.Schema.XSDNode.localName(parent) == "simpleType" else { return [] }
|
||||
let simpleTypesCount = names.count { $0 == "simpleType" }
|
||||
if simpleTypesCount > 1 {
|
||||
errors.append("restriction under simpleType may have at most one inline simpleType")
|
||||
}
|
||||
var seenFacet = false
|
||||
for name in names {
|
||||
if name == "annotation" { continue }
|
||||
if name == "simpleType" {
|
||||
if seenFacet {
|
||||
errors.append("inline simpleType must appear before facets in restriction")
|
||||
}
|
||||
} else if simpleTypeRestrictionAllowedChildren.contains(name) {
|
||||
seenFacet = true
|
||||
}
|
||||
}
|
||||
let hasBase = PureXML.Schema.XSDNode.attribute(node, "base") != nil
|
||||
let hasSimpleType = names.contains("simpleType")
|
||||
if hasBase, hasSimpleType {
|
||||
errors.append("restriction under simpleType cannot have both a 'base' attribute and an inline 'simpleType' child")
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
static func listErrors(_ node: XSDTree, names: [String]) -> [String] {
|
||||
var errors: [String] = []
|
||||
let simpleTypes = names.count { $0 == "simpleType" }
|
||||
if simpleTypes > 1 {
|
||||
errors.append("list may have at most one inline simpleType")
|
||||
}
|
||||
let hasItemType = PureXML.Schema.XSDNode.attribute(node, "itemType") != nil
|
||||
let hasSimpleType = names.contains("simpleType")
|
||||
if hasItemType, hasSimpleType {
|
||||
errors.append("list cannot have both an 'itemType' attribute and an inline 'simpleType' child")
|
||||
}
|
||||
return errors
|
||||
}
|
||||
}
|
||||
92
Tests/AdversarialCriticTests.swift
Normal file
92
Tests/AdversarialCriticTests.swift
Normal file
@ -0,0 +1,92 @@
|
||||
@testable import PureXML
|
||||
import Testing
|
||||
|
||||
@Suite("Adversarial Critic Tests")
|
||||
struct AdversarialCriticTests {
|
||||
@Test("xml prefix on QName references is accepted without explicit xmlns:xml declaration")
|
||||
func test_xmlPrefixOnQNameReference() throws {
|
||||
_ = try PureXML.Schema.Document("""
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
|
||||
<xs:element name="myElement">
|
||||
<xs:complexType>
|
||||
<xs:attribute ref="xml:lang"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
""")
|
||||
}
|
||||
|
||||
@Test("foreign elements and attributes inside simpleType restriction are ignored and accepted")
|
||||
func test_foreignElementsAndAttributesInSimpleType() throws {
|
||||
_ = try PureXML.Schema.Document("""
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:simpleType name="mySimple">
|
||||
<xs:restriction base="xs:string" ext:customAttr="hello" xmlns:ext="http://example.com/ext">
|
||||
<ext:metadata info="extra"/>
|
||||
<xs:minLength value="1"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:schema>
|
||||
""")
|
||||
}
|
||||
|
||||
@Test("complex type check with different namespace configurations and prefixes")
|
||||
func test_complexTypeCheckNamespaceComplexity() throws {
|
||||
// 1. Unprefixed reference to simple type when targetNamespace is default namespace - accepted
|
||||
_ = try PureXML.Schema.Document("""
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns="http://example.com"
|
||||
targetNamespace="http://example.com">
|
||||
<xs:simpleType name="myBaseSimple">
|
||||
<xs:restriction base="xs:string"/>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="mySimple">
|
||||
<xs:restriction base="myBaseSimple"/>
|
||||
</xs:simpleType>
|
||||
</xs:schema>
|
||||
""")
|
||||
|
||||
// 2. Prefixed reference to simple type - accepted
|
||||
_ = try PureXML.Schema.Document("""
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:tns="http://example.com"
|
||||
targetNamespace="http://example.com">
|
||||
<xs:simpleType name="myBaseSimple">
|
||||
<xs:restriction base="xs:string"/>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="mySimple">
|
||||
<xs:restriction base="tns:myBaseSimple"/>
|
||||
</xs:simpleType>
|
||||
</xs:schema>
|
||||
""")
|
||||
|
||||
// 3. Unprefixed reference to simple type in no-targetNamespace schema - accepted
|
||||
_ = try PureXML.Schema.Document("""
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:simpleType name="myBaseSimple">
|
||||
<xs:restriction base="xs:string"/>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="mySimple">
|
||||
<xs:restriction base="myBaseSimple"/>
|
||||
</xs:simpleType>
|
||||
</xs:schema>
|
||||
""")
|
||||
|
||||
// 4. Default namespace set to XSD namespace referencing simple/complex types
|
||||
_ = try PureXML.Schema.Document("""
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://example.com"
|
||||
xmlns:tns="http://example.com">
|
||||
<complexType name="myComplex">
|
||||
<sequence>
|
||||
<element name="a" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
<simpleType name="mySimple">
|
||||
<restriction base="string"/> <!-- restricts xs:string (simple) -->
|
||||
</simpleType>
|
||||
</schema>
|
||||
""")
|
||||
}
|
||||
}
|
||||
@ -142,4 +142,114 @@ struct SchemaSimpleTypeRestrictionTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test("restricting xs:anyType directly in simpleType is rejected")
|
||||
func test_anyTypeRestrictionSimple() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:restriction base="xs:anyType"/>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("unbound QName prefix in simpleType restriction base is rejected")
|
||||
func test_unboundPrefixRestrictionBase() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:restriction base="foo:string"/>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("unbound QName prefix in list itemType is rejected")
|
||||
func test_unboundPrefixListItemType() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:list itemType="foo:integer"/>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("multiple inline simpleType base definitions in restriction is rejected")
|
||||
func test_multipleInlineSimpleTypeRestriction() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:restriction>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string"/>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:integer"/>
|
||||
</xs:simpleType>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("both base attribute and inline simpleType in restriction is rejected")
|
||||
func test_baseAndInlineSimpleTypeRestriction() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string"/>
|
||||
</xs:simpleType>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("anyAttribute inside simpleType restriction is rejected")
|
||||
func test_anyAttributeInSimpleTypeRestriction() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:restriction base="xs:integer">
|
||||
<xs:anyAttribute processContents="lax"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("list with multiple inline simpleTypes is rejected")
|
||||
func test_listWithMultipleInlineSimpleTypes() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:list>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:integer"/>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string"/>
|
||||
</xs:simpleType>
|
||||
</xs:list>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("list with both itemType and inline simpleType is rejected")
|
||||
func test_listWithItemTypeAndInlineSimpleType() {
|
||||
#expect(rejects("""
|
||||
<xs:simpleType name="t1">
|
||||
<xs:list itemType="xs:integer">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:integer"/>
|
||||
</xs:simpleType>
|
||||
</xs:list>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
|
||||
@Test("list itemType referencing a complex type is rejected")
|
||||
func test_listItemTypeComplexType() {
|
||||
#expect(rejects("""
|
||||
<xs:complexType name="myComplex">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string"/>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
<xs:simpleType name="t1">
|
||||
<xs:list itemType="myComplex"/>
|
||||
</xs:simpleType>
|
||||
"""))
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ struct XSTSSuiteTests {
|
||||
/// XSTS` (debug is far slower and the corpus is large). Per-case deviations
|
||||
/// are written to /tmp/xsts-failures.txt for the burn-down.
|
||||
private let knownSchemaValidRejected = 1
|
||||
private let knownSchemaInvalidAccepted = 350
|
||||
private let knownSchemaInvalidAccepted = 333
|
||||
private let knownInstanceValidRejected = 171
|
||||
private let knownInstanceInvalidAccepted = 155
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ irreducible tail. Do not deviate to new features while this is open.
|
||||
| Bucket | Count | Reading |
|
||||
|---|---|---|
|
||||
| valid-schemas-rejected | **72 -> 4** | production target is 0: rejecting a correct schema is the most user-hostile defect (#148). Particle-restriction over-rejection fixed: pointless `maxOccurs=0` particles removed, content-free restriction of an EMPTY base, empty-derived emptiable-base, and (#163) the pairwise check over the normalized content model with occurrence subsumption applied only to same-kind pairings (cross-kind element/group, group/element, group/wildcard match occurrence inside, by effective total range / member). #164 resolved element-ref namespaces by prefix binding (the `particlesJj/Jk/Jm/Jn/Js`, `particlesQ/R` cluster, -28). Content-free (`maxOccurs=0`) derived groups and substitution-group declaration order closed `particlesW006`/`elemZ027_a`; the W3C MapAndSum rule (Sequence:Choice, #165) closed `particlesV003`. Remaining 1 (`particlesZ001`): a documented spec ambiguity (RecurseAsIfGroup; the reference rejects it), not a defect. |
|
||||
| **invalid-schemas-accepted** | **2461 -> 350** | we rarely catch a bad one (facet, default/fixed value, particle-restriction name+type, id, structural content-model, UPA determinism, content order, identity-constraint XPath-subset, wildcard-namespace, final/block, simpleType content, group/wildcard and group/element cardinality, element-ref namespace, sequence/choice MapAndSum, circular type derivation, circular group/attributeGroup/substitution references, attribute-use uniqueness and single-ID, type-excludes-inline-type, ID-typed value-constraint exclusion, all-group reference placement, substitution-member type derivation, default/fixed mutual exclusion, elementTypeRestrictionOK NameAndTypeOK union checks, prohibited attribute type-check bypass, keyref arity verification, top-level group/attributeGroup local-attribute checks landed). |
|
||||
| **invalid-schemas-accepted** | **2461 -> 333** | we rarely catch a bad one (facet, default/fixed value, particle-restriction name+type, id, structural content-model, UPA determinism, content order, identity-constraint XPath-subset, wildcard-namespace, final/block, simpleType content, group/wildcard and group/element cardinality, element-ref namespace, sequence/choice MapAndSum, circular type derivation, circular group/attributeGroup/substitution references, attribute-use uniqueness and single-ID, type-excludes-inline-type, ID-typed value-constraint exclusion, all-group reference placement, substitution-member type derivation, default/fixed mutual exclusion, elementTypeRestrictionOK NameAndTypeOK union checks, prohibited attribute type-check bypass, keyref arity verification, top-level group/attributeGroup local-attribute checks, simpleType restriction structure and prefix binding checks landed). |
|
||||
| valid-instances-rejected | **233 -> 171** | (instance side; #164's element-ref namespace fix is shared with instance validation, complexContent restriction attributes inheritance and namespace fixes) |
|
||||
| invalid-instances-accepted | **160 -> 155** | (instance side; resolving inline `<simpleType>` restriction base, complexContent restriction attributes prohibition) |
|
||||
|
||||
|
||||
@ -33,10 +33,10 @@ entries removed about 70 apparent deviations that were never bugs.
|
||||
|
||||
| Kind | First measurement | Now |
|
||||
|---|---|---|
|
||||
| valid schema rejected | 75 | 72 |
|
||||
| invalid schema accepted | 2467 | 2461 |
|
||||
| valid instance rejected | 604 | 308 |
|
||||
| invalid instance accepted | 582 | 165 |
|
||||
| valid schema rejected | 75 | 1 |
|
||||
| invalid schema accepted | 2467 | 333 |
|
||||
| valid instance rejected | 604 | 171 |
|
||||
| invalid instance accepted | 582 | 155 |
|
||||
|
||||
Counts are against *settled* W3C expectations (queried/disputed entries excluded).
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user