diff --git a/CHANGELOG.md b/CHANGELOG.md index 003d48b..e30109f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- A tab now ends a leading indicator the way a space does, since a tab is separation white space in + YAML (only indentation forbids a tab). A document marker, block entry, or explicit key followed by a + tab (`---\tscalar`, `-\titem`, `?\tkey`) is recognized as the indicator rather than folded into a + plain scalar. Raises yaml-test-suite value-level conformance to 175/192 (91.1%), with the parse and + should-error rates unchanged. + - A flow sequence element that begins with `:` is now parsed as a single-pair mapping with an empty (null) key, e.g. `[ : value ]` is `[{null: value}]`. The parser raised "expected a YAML node" for the leading `:`; it now emits the empty-key mapping, mirroring the way `[ a: b ]` (a scalar key diff --git a/Sources/Parsing/Scanner.Helpers.swift b/Sources/Parsing/Scanner.Helpers.swift index 9010173..33df47b 100644 --- a/Sources/Parsing/Scanner.Helpers.swift +++ b/Sources/Parsing/Scanner.Helpers.swift @@ -44,7 +44,9 @@ extension PureYAML.Parsing.Scanner { guard let character else { return true } - return character == " " || isLineBreak(character) + // A tab is separation white space in YAML (only indentation forbids it), so it ends an + // indicator just as a space does: `---\tscalar`, `-\titem`, `?\tkey`. + return character == " " || character == "\t" || isLineBreak(character) } func isMappingValueBoundary(_ character: Character?) -> Bool { diff --git a/Tests/IndicatorTabBoundaryTests.swift b/Tests/IndicatorTabBoundaryTests.swift new file mode 100644 index 0000000..8de4107 --- /dev/null +++ b/Tests/IndicatorTabBoundaryTests.swift @@ -0,0 +1,24 @@ +@testable import PureYAML +import Testing + +/// A tab is separation white space in YAML (only indentation forbids a tab), so it ends a leading +/// indicator exactly as a space does. A document marker, block entry, or explicit key followed by a +/// tab is recognized as the indicator, not folded into a plain scalar. +@Suite("Indicator tab boundary") +struct IndicatorTabBoundaryTests { + @Test("A document marker followed by a tab introduces an inline root scalar") + func test_documentMarkerTab() throws { + #expect(try PureYAML.parse("---\tscalar\n") == .string("scalar")) + } + + @Test("A block entry indicator followed by a tab still starts a sequence item") + func test_blockEntryTab() throws { + #expect(try PureYAML.parse("-\titem\n") == .sequence([.string("item")])) + } + + @Test("A space after an indicator is unchanged") + func test_spaceStillWorks() throws { + #expect(try PureYAML.parse("--- scalar\n") == .string("scalar")) + #expect(try PureYAML.parse("- item\n") == .sequence([.string("item")])) + } +}