diff --git a/CHANGELOG.md b/CHANGELOG.md index ee5ea65..73da913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Accept a tab as block-scalar content once the indentation is satisfied. The + block-scalar break scanner rejected any tab seen while auto-detecting the + content indentation, but a tab at or beyond the content column is content, not + indentation. The tab is now an error only below the content column (the parent + indent + 1 floor while auto-detecting), so `foo: |-` / `bar` lines whose + content begins with a tab parse, while a tab used as indentation (a tab-only + line shallower than the content) is still rejected. Surpasses libyaml on + 96NN/00, 96NN/01, R4YG, and Y79Y/001. - Auto-detect indentation 0 for a root-level block scalar. The block-scalar scanner used 0 as the "indentation not yet detected" sentinel and floored the detected indent at 1 (as libyaml does in `scan_block_scalar_breaks`), so a diff --git a/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift b/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift index 05def72..81b0bc4 100644 --- a/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift +++ b/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift @@ -107,6 +107,10 @@ extension PureYAML.Parsing.LibYAML.Scanner { private mutating func scanBlockScalarBreaks(indent: inout Int, state: inout BlockState, startMark: PureYAML.Parsing.Mark, endMark: inout PureYAML.Parsing.Mark) throws { var maxIndent = 0 endMark = reader.mark + // A tab is content (or separation) once the column reaches the content + // indentation; it is illegal only while still inside the required + // indentation. During auto-detection the floor is the parent indent + 1. + let tabFloor = indent >= 0 ? indent : max(0, indentEngine.indent + 1) while true { while indent < 0 || reader.column < indent, reader.peek() == " " { reader.skip() @@ -114,7 +118,7 @@ extension PureYAML.Parsing.LibYAML.Scanner { if reader.column > maxIndent { maxIndent = reader.column } - if indent < 0 || reader.column < indent, Classify.isTab(reader.peek()) { + if reader.column < tabFloor, Classify.isTab(reader.peek()) { throw blockError("found a tab character where an indentation space is expected", startMark) } if !Classify.isBreak(reader.peek()) { diff --git a/Tests/CanonicalEventConformanceTests.swift b/Tests/CanonicalEventConformanceTests.swift index 5237e00..81bbb6c 100644 --- a/Tests/CanonicalEventConformanceTests.swift +++ b/Tests/CanonicalEventConformanceTests.swift @@ -12,7 +12,7 @@ struct CanonicalEventConformanceTests { /// Valid suite cases whose event stream PureYAML does NOT yet emit exactly. /// This is the authoritative gap set: a fix removes an id (and the test fails /// until it is removed), a regression adds one (and the test fails). Of these, - /// 18 currently throw on valid input and 4 emit a wrong event stream. + /// 14 currently throw on valid input and 4 emit a wrong event stream. static let knownEventGaps: Set = [ // Gap set for the ported libyaml engine. Verified against the libyaml // reference dumper: on all but four of these the port matches libyaml @@ -22,10 +22,10 @@ struct CanonicalEventConformanceTests { // // false-rejects (parseEvents throws on valid input, as libyaml does) "4ABK", "58MP", "5T43", "6BCT", "6CA3", - "96NN/00", "96NN/01", "A2M4", "CFD4", "DBG4", "DK95/00", + "A2M4", "CFD4", "DBG4", "DK95/00", "DK95/04", "FRK4", "HM87/00", - "Q5MG", "R4YG", - "Y79Y/001", "Y79Y/010", + "Q5MG", + "Y79Y/010", // wrong event stream: the port matches libyaml but both deviate from the // canonical events (libyaml quirks to be surpassed). "652Z", "HM87/01", "JEF9/02", "W4TN",