diff --git a/Sources/Parsing/LibYAML.Scanner.Fetch.swift b/Sources/Parsing/LibYAML.Scanner.Fetch.swift index 3edc334..86724cf 100644 --- a/Sources/Parsing/LibYAML.Scanner.Fetch.swift +++ b/Sources/Parsing/LibYAML.Scanner.Fetch.swift @@ -25,6 +25,15 @@ extension PureYAML.Parsing.LibYAML.Scanner { while reader.peek() == " " || ((flowLevel > 0 || !simpleKeyAllowed) && reader.peek() == "\t") { reader.skip() } + // YAML 1.2: a line containing only whitespace is blank even when that + // whitespace includes tabs. libyaml leaves a leading tab in place and + // later rejects it; instead consume the trailing blanks so the line + // break below is reached and the blank line is skipped. + if blankLineAhead() { + while reader.peek() == " " || Classify.isTab(reader.peek()) { + reader.skip() + } + } if reader.peek() == "#" { while !Classify.isBreakZ(reader.peek()) { reader.skip() @@ -301,6 +310,16 @@ extension PureYAML.Parsing.LibYAML.Scanner { indentEngine.enqueue(token) } + /// Whether the rest of the current line, from the current position, is only + /// spaces and tabs up to a line break or end of stream (a blank line). + private func blankLineAhead() -> Bool { + var offset = 0 + while let character = reader.peek(offset), character == " " || Classify.isTab(character) { + offset += 1 + } + return Classify.isBreakZ(reader.peek(offset)) + } + private func isDocumentMarker(_ character: Unicode.Scalar) -> Bool { reader.peek(0) == character && reader.peek(1) == character diff --git a/Tests/CanonicalEventConformanceTests.swift b/Tests/CanonicalEventConformanceTests.swift index e2b5e22..93323c5 100644 --- a/Tests/CanonicalEventConformanceTests.swift +++ b/Tests/CanonicalEventConformanceTests.swift @@ -24,7 +24,7 @@ struct CanonicalEventConformanceTests { "2JQS", "2SXE", "4ABK", "4MUZ/00", "4MUZ/01", "4MUZ/02", "58MP", "5MUD", "5T43", "6BCT", "6CA3", "6M2F", "7Z25", "8XYN", "96NN/00", "96NN/01", "9SA2", "A2M4", "CFD4", "DBG4", "DK3J", "DK95/00", - "DK95/03", "DK95/04", "FP8R", "FRK4", "HM87/00", "HWV9", "K3WX", "M2N8/00", + "DK95/04", "FP8R", "FRK4", "HM87/00", "HWV9", "K3WX", "M2N8/00", "M7A3", "NHX8", "NJ66", "NKF9", "Q5MG", "QT73", "R4YG", "S3PD", "SM9W/01", "UKK6/00", "UT92", "VJP3/01", "W4TN", "W5VH", "Y79Y/001", "Y79Y/010",