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
I'm not well-versed enough in the YAML spec to tell you what the proper terms are to use in this bug report. It seems to be in "block mode" (?) rendering of long strings starting with spaces.
They don't need to contain newlines to trigger the issue, but if they do the newlines are lost.
The issue is in rendering, not parsing, as all YAML engines seem to parse the string the same (which is different from the original string).
Summary
If the renderer switches to some particular rendering mode marked by ">-2" (seems to be triggered by the string starting with a space) then if word wrap occurs the word wrap is interpreted as a literal newline. Actual newlines that are in this block will be lost upon parsing as well.
A string that looks like this:
" very long string that will cause wrapping. \n a newline"
Will render like this:
field: >-2
very long string that will cause
wrapping.
a newline
And when parsed back will be parsed as:
" very long string that will cause \n wrapping. a newline"
So the wrap is interpreted as a newline and the actual newline is lost.
Repro
Here is the reproduction (still occurs with version 1.0.3).
constYAML=require('yaml');constassert=require('assert');constobj={Field: ' very long line that starts with a space. very long line that starts with a space.\nstart on a new line'};constyamlified=YAML.stringify(obj);console.log(yamlified);constparsed=YAML.parse(yamlified);assert.deepEqual(obj,parsed);
Output:
Field: >-2
very long line that starts with a space. very long line that starts with a
space.
start on a new line
Assertion fails:
AssertionError [ERR_ASSERTION]: { Field: ' very long line that starts with a space. very long line that starts with a space.\nstart on a new line' } deepEqual { Field: ' very long line that starts with a space. very long line that starts with a\nspace. start on a new line' }
NOTE: We're normally using this library in yaml-1.1 mode (because we're generating output for AWS CloudFormation), but this issue also crops up in YAML 1.2 mode as the repro shows.
The text was updated successfully, but these errors were encountered:
The bug was that the check for more-indented lines (which should not be folded) in a folded block scalar was not triggering on the first content line. Thank you for catching it!
I'm not well-versed enough in the YAML spec to tell you what the proper terms are to use in this bug report. It seems to be in "block mode" (?) rendering of long strings starting with spaces.
They don't need to contain newlines to trigger the issue, but if they do the newlines are lost.
The issue is in rendering, not parsing, as all YAML engines seem to parse the string the same (which is different from the original string).
Summary
If the renderer switches to some particular rendering mode marked by ">-2" (seems to be triggered by the string starting with a space) then if word wrap occurs the word wrap is interpreted as a literal newline. Actual newlines that are in this block will be lost upon parsing as well.
A string that looks like this:
Will render like this:
And when parsed back will be parsed as:
So the wrap is interpreted as a newline and the actual newline is lost.
Repro
Here is the reproduction (still occurs with version 1.0.3).
Output:
Assertion fails:
NOTE: We're normally using this library in
yaml-1.1
mode (because we're generating output for AWS CloudFormation), but this issue also crops up in YAML 1.2 mode as the repro shows.The text was updated successfully, but these errors were encountered: