fix(parsing): reject content after a document-end marker

A '...' may be followed only by whitespace and a comment on its line.
Unlike '--- x', which carries inline document content, '... x' is
malformed, but the port (like libyaml) parsed the trailing text as a new
bare document.

After emitting the document-end token, require the rest of the line to be
blank or a comment. Surpasses libyaml on 3HFZ; whole-suite conformance
392/402, canonical events 308/308.
This commit is contained in:
Mihaela Mihaljevic 2026-06-24 20:13:51 +02:00
parent fca1441a27
commit 4a6b168565
3 changed files with 23 additions and 6 deletions

View File

@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Reject content after a `...` document-end marker on the same line. Only
whitespace and a comment may follow `...`; unlike `--- x`, a `... x` cannot
carry inline content. Surpasses libyaml on 3HFZ.
- Resolve a scalar with the non-specific `!` tag as a string. The `!` tag forces
resolution by kind alone, with no implicit typing, so `! 12` is the string "12"
rather than the integer 12. The typed value now honours it (the event stream

View File

@ -45,11 +45,11 @@ extension PureYAML.Parsing.LibYAML.Scanner {
return
}
if reader.column == 0, isDocumentMarker("-") {
fetchDocumentIndicator(.documentStart)
try fetchDocumentIndicator(.documentStart)
return
}
if reader.column == 0, isDocumentMarker(".") {
fetchDocumentIndicator(.documentEnd)
try fetchDocumentIndicator(.documentEnd)
return
}
guard let character else {
@ -255,7 +255,7 @@ extension PureYAML.Parsing.LibYAML.Scanner {
}
/// Port of `yaml_parser_fetch_document_indicator`.
private mutating func fetchDocumentIndicator(_ type: PureYAML.Parsing.LibYAML.TokenType) {
private mutating func fetchDocumentIndicator(_ type: PureYAML.Parsing.LibYAML.TokenType) throws {
indentEngine.unrollIndent(column: -1, mark: reader.mark)
simpleKeys[simpleKeys.count - 1].possible = false
simpleKeyAllowed = false
@ -264,6 +264,20 @@ extension PureYAML.Parsing.LibYAML.Scanner {
reader.skip()
reader.skip()
indentEngine.enqueue(Token(type: type, startMark: startMark, endMark: reader.mark))
if case .documentEnd = type {
// Only whitespace and a comment may follow `...` on its line; a `--- x`
// document start can carry inline content, but `... x` cannot.
while reader.peek() == " " || Classify.isTab(reader.peek()) {
reader.skip()
}
if let next = reader.peek(), next != "#", !Classify.isBreak(next) {
throw ScannerError(
context: "while scanning a document end marker",
problem: "found content after the document end marker",
mark: reader.mark,
)
}
}
}
/// Port of `yaml_parser_fetch_block_entry`.

View File

@ -10,8 +10,8 @@ source:
# oracle: json if in.json present, else none
# status: passing (PureYAML conformant today) | gap (not yet conformant)
total: 402
passing: 391
gap: 11
passing: 392
gap: 10
cases:
- id: "229Q"
name: "Spec Example 2.4. Sequence of Mappings"
@ -178,7 +178,7 @@ cases:
localPath: yaml-test-suite/3HFZ/in.yaml
expected: reject
oracle: none
status: gap
status: passing
byteCount: 27
lineCount: 3
- id: "3MYT"