fix(schema): preserve list/union variety through a simpleContent derivation (#147)
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. simpleContentType built the content type with only the resolved base and facets, dropping the variety, so a list-typed simpleContent accepted any whitespace-separated text and an invalid item (e.g. a non-int in a list of int) was not caught. A valid list/union value is unaffected; the change only tightens validation of content that was wrongly accepted. The W3C XSTS corpus does not exercise this case, so all four bucket counts are unchanged (vsr=0, isa=67, vir=0, ivi=31); the gap was surfaced by the libxml2 differential and is covered by a unit test.
This commit is contained in:
parent
0167c92790
commit
872e6ea7d0
@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- 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.)
|
||||
|
||||
- XSTS invalid-schemas-accepted (#145): a substitution-group member whose type is a list or union derives only from `anySimpleType`, so it may affiliate only to a head typed `anySimpleType` (or to the same type, or as a recorded restriction of the head's type). The substitution-type check skipped derivation entirely when either the member or head type was a list/union; a list/union-typed member affiliated to an unrelated head type (addB141: a union member of a list-typed head) is now rejected, while a list/union member of an `anySimpleType` head and a restriction of a list head remain valid. invalid-schemas-accepted 69 → 67, no false positive (valid-schemas-rejected and valid-instances-rejected held at 0), no other bucket moved.
|
||||
|
||||
- XSTS invalid-instances-accepted (#147): a `block` on a LOCAL element declaration is now keyed by the element's instance (qualified) name in the derivation backbone, so an xsi:type substitution blocked on an unqualified local element is barred. The namespaced backbone keyed every element by the target namespace, but a local element is in the target namespace only when qualified (its own `form`, else the schema's elementFormDefault); an unqualified local element's block went unfound (typeDef00801). invalid-instances-accepted 32 → 31, no false positive (valid-instances-rejected and valid-schemas-rejected held at 0), no other bucket moved.
|
||||
|
||||
@ -377,7 +377,7 @@ extension PureXML.Schema.XSDParser {
|
||||
let baseType = simpleContentBaseType(baseName, uri: uri, context, visited: visited)
|
||||
var facets = baseType.facets
|
||||
XSDSimpleParser.applyFacets(inner, into: &facets)
|
||||
return SimpleType(base: baseType.base, facets: facets)
|
||||
return SimpleType(base: baseType.base, facets: facets, variety: baseType.variety, isBuiltinList: baseType.isBuiltinList)
|
||||
}
|
||||
|
||||
/// The simple type a `simpleContent` derivation derives from: an XSD built-in, a
|
||||
|
||||
31
Tests/SchemaSimpleContentListTests.swift
Normal file
31
Tests/SchemaSimpleContentListTests.swift
Normal file
@ -0,0 +1,31 @@
|
||||
@testable import PureXML
|
||||
import Testing
|
||||
|
||||
/// A complex type whose `simpleContent` derives from a list or union simple type
|
||||
/// keeps that variety, so its element content is validated as a list/union rather
|
||||
/// than collapsing to an atomic value space. A `simpleContent` extension of a
|
||||
/// list-of-int validates its text as a list of ints: a non-int item is rejected.
|
||||
@Suite("simpleContent list/union variety")
|
||||
struct SchemaSimpleContentListTests {
|
||||
private func schema() throws -> PureXML.Schema.Document {
|
||||
try PureXML.Schema.Document("""
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:simpleType name="ints"><xs:list itemType="xs:int"/></xs:simpleType>
|
||||
<xs:complexType name="CT"><xs:simpleContent>
|
||||
<xs:extension base="ints"><xs:attribute name="a" type="xs:string"/></xs:extension>
|
||||
</xs:simpleContent></xs:complexType>
|
||||
<xs:element name="e" type="CT"/>
|
||||
</xs:schema>
|
||||
""")
|
||||
}
|
||||
|
||||
@Test("a valid int-list simpleContent is accepted")
|
||||
func test_validListAccepted() throws {
|
||||
#expect(try schema().validate(#"<e a="x">1 2 3</e>"#).isEmpty)
|
||||
}
|
||||
|
||||
@Test("a non-int item in a list simpleContent is rejected")
|
||||
func test_invalidListItemRejected() throws {
|
||||
#expect(try !schema().validate(#"<e a="x">1 z 3</e>"#).isEmpty)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user