diff --git a/CHANGELOG.md b/CHANGELOG.md index 510b08d..cf1bdc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Sources/Parsing/LibYAML.Scanner.Fetch.swift b/Sources/Parsing/LibYAML.Scanner.Fetch.swift index b3b6d02..c0622fc 100644 --- a/Sources/Parsing/LibYAML.Scanner.Fetch.swift +++ b/Sources/Parsing/LibYAML.Scanner.Fetch.swift @@ -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`. diff --git a/Tests/Fixtures/yaml-test-suite-manifest.yaml b/Tests/Fixtures/yaml-test-suite-manifest.yaml index 1bb1ea0..8b307c1 100644 --- a/Tests/Fixtures/yaml-test-suite-manifest.yaml +++ b/Tests/Fixtures/yaml-test-suite-manifest.yaml @@ -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"