A line that begins with a document marker ('---' or '...') followed by a
boundary is forbidden inside a multi-line scalar, since it is ambiguous
with a document boundary. A multi-line quoted scalar folded such a line
into its value instead of rejecting it.
scanQuotedScalar now checks, on crossing each line break, whether the next
line begins a document marker, and rejects the scalar if so. The check
requires the marker at the line start with a following boundary, so inline
dashes ('a --- b'), '---' with no boundary ('---b'), an indented '---',
and dots not at a line start stay ordinary content.
Measured against the official YAML test-suite, parse-level conformance
rises from 268/333 (80.5%) to 270/333 (81.1%) with no regression.
26 lines
1020 B
Swift
26 lines
1020 B
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Document markers inside multi-line scalars")
|
|
struct DocumentMarkerInScalarTests {
|
|
@Test("A `---` or `...` line inside a multi-line quoted scalar is rejected", arguments: [
|
|
"---\n\"\n---\n\"\n", // a `---` line inside a double-quoted scalar
|
|
"---\n'\n...\n'\n", // a `...` line inside a single-quoted scalar
|
|
])
|
|
func test_documentMarkerInScalarRejected(_ yaml: String) throws {
|
|
#expect(throws: PureYAML.Parsing.ParseError.self) {
|
|
try PureYAML.parse(yaml)
|
|
}
|
|
}
|
|
|
|
@Test("Dashes and dots that are not a line-start marker stay valid", arguments: [
|
|
"\"a --- b\"\n", // dashes inline, not at a line start
|
|
"\"a\n---b\"\n", // `---` without a following boundary is content
|
|
"\"a\nb\"\n", // an ordinary multi-line quoted scalar
|
|
"\"...x\"\n", // dots not at a line start
|
|
])
|
|
func test_nonMarkerContentStaysValid(_ yaml: String) throws {
|
|
_ = try PureYAML.parse(yaml)
|
|
}
|
|
}
|