Fix block scalar leading/trailing newlines#278
Conversation
|
Added a hotfix for double-quoted. |
|
Sorry for so delayed reply! Could you make Also, this fixes only first part of #253, am I right? |
|
if |
|
I prefer boolean too for style. Originally I wrote it like you said. There's another neat solution though: represent '\n' directly rather than converting it from 1 or true each time. The new commit uses this method to avoid almost all conversions and branching. It has the best performance and, I believe, good readability. What do you think? Benchmarks For part 2 of #253, it appears the spec has an error.
(Rule [175] for folded lines doesn't match) LibYAML 0.1.5 agrees. |
| // Just one line break - perceive as the same line. | ||
| } else if (emptyLines === 0) { | ||
| if (didReadContent) { // i.e. only if we have already read some scalar content. | ||
| if (contentNewline) { // i.e. only if we have already read some scalar content. |
There was a problem hiding this comment.
Or !== ''. I'd expect all of them to have about the same performance, since the type of contentNewline is fully determined as non-null string at compile time.
There was a problem hiding this comment.
I mean, we avoid indirect type casts and string operations when possible.
a7fce25 to
0d7af25
Compare
|
It doesn't seem to really affect the benchmarks in my opinion. The difference seem to be in the margin of error. I'd propose to stick to Boolean solution @puzrin proposed. |
|
@dervus any more notes? Ok to squash and merge? |
|
Yes, looks good to me. Thanks, @aepsilon. |
|
@aepsilon could you squash 2 last commits into the first one? |
Fixes nodeca#253: loader should not add an extra newline at the beginning of block scalars that have an explicit indentation indicator. Cause: "Detected indent" was assumed logically equivalent to "did read non-empty line". This no longer holds with an indentation indicator: indent is detected before any content is read. Fixes nodeca#276: loader should not remove a trailing newline for block scalars with "+" chomping. Cause: "+" chomping didn't account for the last content newline before the trailing empty lines.
Taken from scalar_double_quoted_simple_multiline.yaml
8807e73 to
10d82a2
Compare
|
Done. 👍 Thanks for checking it over. |
|
Seems ok to release. 3.6.0 or 4.0.0? Can it break something? |
|
Well, it's not an API change, though it changes dumper output. However I saw some NodeJS folks talking about changes of dump output. It was somewhere at PRs/issues external references. I'd bet for minor version change. |
Fixes #253: loader should not add an extra newline at the beginning of block scalars that have an explicit indentation indicator.
Cause: "Detected indent" was assumed logically equivalent to "did read non-empty line".
This no longer holds with an indentation indicator: indent is detected before any content is read.
Fixes #276: loader should not remove a trailing newline for block scalars with "+" chomping.
Cause: "+" chomping didn't account for the last content newline before the trailing empty lines.
I'm not 100% familiar with the loader so there may be some missed edge cases.
So far it's passed every test I've tried.
@dervus and @puzrin, I hope this helps. Let me know if you find something.