You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser truncates trailing newlines in multiline quoted scalars #1511
With yaml-cpp 0.9.0 or the current master (c5e65360), parsing the following multiline single-quoted scalar appears to lose one trailing newline:
value: 'a b'
Expected value:
"a\nb\n\n"
Actual value:
"a\nb\n"
The YAML above was generated by PyYAML's safe_dump, and PyYAML reads it back as the expected five-byte string. Equivalent double-quoted and literal-block representations also produce the expected value in yaml-cpp.
Could it be that your double_quoted example is false?
The backslash of \n should not be escaped:
const auto double_quoted =
YAML::Load("value: \"a\nb\n\n\"\n")["value"].as<std::string>();
This would mean that the issue does not only appear with 'single-quoted scalar' but also with 'double-quoted scalars'.
(This is also what I would assume happens, when looking at your PR).
The biggest question I know have is: Why did we not notice this error earlier?
I confirm that this also happens with multiline double-quoted scalars, and the regression test in #1512 covers both quote styles. I'll update the issue title.
The \\n is intentional: it produces the following YAML, containing \n escape sequences:
value: "a\nb\n\n"
This was included as a control case (it preserves the expected value, whereas the equivalent representation using physical line breaks loses a trailing newline).
As for why it went unnoticed, I guess this edge case is uncommon and usually doesn't produce obvious effects. I noticed it while trying to reach parity with the Rust implementation of an internal tool.
changed the title [-]Parser drops a trailing newline in a multiline single-quoted scalar[/-][+]Parser truncates trailing newlines in multiline quoted scalars[/+]on Oct 15, 2026
Activity
SGSSGene commentedon Oct 15, 2026
Thank you for reporting and sending in a PR.
Could it be that your
double_quotedexample is false?The backslash of
\nshould not be escaped:This would mean that the issue does not only appear with 'single-quoted scalar' but also with 'double-quoted scalars'.
(This is also what I would assume happens, when looking at your PR).
The biggest question I know have is: Why did we not notice this error earlier?
LucaCiucci commentedon Oct 15, 2026
Hi @SGSSGene, thank you for looking into this.
I confirm that this also happens with multiline double-quoted scalars, and the regression test in #1512 covers both quote styles. I'll update the issue title.
The
\\nis intentional: it produces the following YAML, containing\nescape sequences:This was included as a control case (it preserves the expected value, whereas the equivalent representation using physical line breaks loses a trailing newline).
As for why it went unnoticed, I guess this edge case is uncommon and usually doesn't produce obvious effects. I noticed it while trying to reach parity with the Rust implementation of an internal tool.
[-]Parser drops a trailing newline in a multiline single-quoted scalar[/-][+]Parser truncates trailing newlines in multiline quoted scalars[/+]