diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f0d783..fe41ece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- A `mixed="true"` complex type with no content model now permits character data (#147). Such a type (only attributes, no `sequence`/`choice`/`all`) was compiled to the empty content type, which forbids text, so a mixed element carrying only text was rejected. It is now mixed content over an empty particle: text is allowed, child elements are still not. XSTS: valid instances rejected 311 to 308. - `` references to global attribute declarations are now resolved (#147). A reference has no `name`, so it was dropped and the referenced attribute looked undeclared on the instance; nested attribute-group references were already flattened, but the per-attribute reference was not. The reference now resolves to the global declaration's type, taking `use`/`default`/`fixed` from the reference site. XSTS: valid instances rejected 338 to 311. - Document-scoped `xs:ID`/`xs:IDREF` validation is now enforced (#147). `xs:ID`, `xs:IDREF`, and `xs:IDREFS` were checked only lexically (as NCNames); the document-wide constraints, that every ID is unique and every IDREF/IDREFS item matches some ID, were not. The tree validator now records ID and reference values during its typed walk (elements and attributes) and reports duplicate IDs and unresolved references once the whole document is seen, so a forward reference resolves against a later ID. XSTS: invalid instances accepted 179 to 166. - The regex `\w` and `\W` escapes now follow the XSD definition (#147). `\w` was the Perl class (alphabetic, decimal, underscore); XSD defines it as `[#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}]`, so symbols and marks are word characters and the connector `_` (Pc) is not. `\W` correspondingly matched symbols it should not. XSTS: invalid instances accepted 231 to 210. (Internal regex fixtures that assumed `_` was a word character were corrected.) diff --git a/Sources/Schema/XSDParser.swift b/Sources/Schema/XSDParser.swift index 72100ad..f74f01c 100644 --- a/Sources/Schema/XSDParser.swift +++ b/Sources/Schema/XSDParser.swift @@ -148,7 +148,14 @@ extension PureXML.Schema { } let wildcard = attributeWildcard(under: node, context) guard let particle = modelGroup(in: node, context) else { - return ComplexType(attributes: attributes, attributeWildcard: wildcard, content: .empty) + // A mixed type with no content model still permits character data + // (just no child elements): mixed content over an empty particle, + // not the empty content type, which forbids text. + guard mixed else { + return ComplexType(attributes: attributes, attributeWildcard: wildcard, content: .empty) + } + let emptyParticle = Particle(term: .group(.init(compositor: .sequence, particles: []))) + return ComplexType(attributes: attributes, attributeWildcard: wildcard, content: .mixed(emptyParticle)) } return ComplexType(attributes: attributes, attributeWildcard: wildcard, content: mixed ? .mixed(particle) : .elementOnly(particle)) } diff --git a/Tests/SchemaMixedEmptyTests.swift b/Tests/SchemaMixedEmptyTests.swift new file mode 100644 index 0000000..abbf3b0 --- /dev/null +++ b/Tests/SchemaMixedEmptyTests.swift @@ -0,0 +1,34 @@ +@testable import PureXML +import Testing + +/// A `mixed="true"` complex type with no content model (only attributes) still +/// permits character data: it is mixed content over an empty particle, not the +/// empty content type, which forbids text (#147, XSTS attgD set). Child elements +/// are still not allowed, and a non-mixed empty type still rejects text. +@Suite("Mixed content with no element model") +struct SchemaMixedEmptyTests { + private func schema(mixed: Bool) throws -> PureXML.Schema.Document { + try PureXML.Schema.Document(""" + + + + + + + + """) + } + + @Test("A mixed empty type permits text and stays empty of elements") + func test_mixedAllowsText() throws { + let doc = try schema(mixed: true) + #expect(try doc.validate(#"hello"#).isEmpty) // text allowed + #expect(try doc.validate(#""#).isEmpty) // empty allowed + #expect(try !doc.validate(#""#).isEmpty) // no element content + } + + @Test("A non-mixed empty type still rejects text") + func test_nonMixedRejectsText() throws { + #expect(try !schema(mixed: false).validate(#"hello"#).isEmpty) + } +} diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift index 6daf15b..9715550 100644 --- a/Tests/XSTSSuiteTests.swift +++ b/Tests/XSTSSuiteTests.swift @@ -30,7 +30,7 @@ struct XSTSSuiteTests { /// are written to /tmp/xsts-failures.txt for the burn-down. private let knownSchemaValidRejected = 72 private let knownSchemaInvalidAccepted = 2461 - private let knownInstanceValidRejected = 311 + private let knownInstanceValidRejected = 308 private let knownInstanceInvalidAccepted = 165 @Test("Every XSTS case behaves: compile, reject, validate, invalidate")