From 37e84b5eb443496008ae5c1638e5e9ad438b0548 Mon Sep 17 00:00:00 2001 From: Mihaela M Date: Sun, 28 Jun 2026 20:19:16 +0200 Subject: [PATCH] fix(parsing): accept a tab as a leading indicator boundary A tab is separation white space in YAML, forbidden only for indentation, so it ends a leading indicator exactly as a space does. isIndicatorBoundary treated only a space, line break, or end of input as a boundary, so a document marker, block entry, or explicit key followed by a tab was folded into a plain scalar: `---\tscalar` parsed to the string `---\tscalar` rather than a document whose root scalar is `scalar`. Accept a tab there too. The document-marker and block-entry forms also strip the tab as separation, so the content is clean; the explicit-key form is now recognized as well, with post-indicator tab stripping left for a later change. Raises yaml-test-suite value-level conformance to 175/192 (91.1%) with the parse-level and should-error rejection rates unchanged. 429 tests pass. --- CHANGELOG.md | 6 ++++++ Sources/Parsing/Scanner.Helpers.swift | 4 +++- Tests/IndicatorTabBoundaryTests.swift | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Tests/IndicatorTabBoundaryTests.swift 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")])) + } +}