-
-
Notifications
You must be signed in to change notification settings - Fork 805
Rewrite scalar dumper for correctness #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Rewrote the scalar dumper with an emphasis on rigor, based on a careful reading of the YAML 1.2 spec and testing against LibYAML. Corrections: Block style chomping accounts for added the extra newline added by subsequent elements or at the end. Fixes nodeca#238. Top-level block scalars are indented. Fixes dumper side of nodeca#221. Folded style should be reliable now. The old dumper was not aware of the subtle rules for more-indented lines. More-indented lines no longer cause extra newlines to be added. (The old dumper also had an off-by-one error that dropped the last character from a long first word on a line.) Fixes nodeca#215, nodeca#222. Removes nodeca#217 workaround. Literal and folded styles can represent arbitrary "printable" strings, including leading/trailing whitespace. NB. For the 'construct-string-types' dumper test, the strings are dumped correctly. The test fails because a loader bug loses a newline when using the keep "+" chomping indicator. Additional: Added test suite covering several former bugs, new edge cases, and new expected behaviors. All previous applicable tests are included. Styles are chosen in a well-defined order. Plain and single are preferred for single lines under the width limit. Folded is preferred when a line is longer than the width limit (if enabled) and does not begin with a space. Literal is used for all other multi-line "printable" strings. Double-quoted is only used when a string is unrepresentable otherwise. Plain style is relaxed to include more characters and strings. Progress on nodeca#183. As indent increases, line width decreases down to min(lineWidth, 40). Setting lineWidth to -1 disables wrapping. Previously there was unexpected behavior past 40 indent: narrow lineWidth suddenly jumped to 40, and -1 (no limit) suddenly enforced a limit of 40.
test/issues/0217.js
Outdated
|
|
||
|
|
||
| test('Javascript functions are not folded', function () { | ||
| test.skip('Javascript functions are not folded', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are those tests skipped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @dervus expected, the actual problem was the folded style dumper was buggy. It tried to break more-indented lines, which resulted in newlines being added. Folding more-indented lines is not allowed in YAML.
Now that the folder is fixed it should work for all (applicable) string data regardless of content.
This line tests for a workaround that doesn't fix the root problem (see #222).
Although I think it's better that the root problem is fixed, I can add the workaround back in if desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, tests were added to check that fns & regexes are not broken. I don't mean tests should stay intact, but those should continue to work. There are no need to disable those cimpletely, for historic reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naturally, we want to make sure they continue to work.
The dumper doesn't differentiate between tags anymore. The current test demands no folded style, even though the data is dumped correctly. Keeping the test as-is means putting the workaround back in the dumper.
I could change the test to dump then load several examples of functions and regexes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, update tests to reflect your changes. No workaround in dumper needed.
|
Very impressing. This week surprised me so much - 2 PRs (here & in @dervus could you take a look? |
|
I can take a look on the weekend. Very busy right now, sorry. |
Updated test for nodeca#217. It now checks that folded style preserves JS functions and regexps. Replaced String.prototype.repeat with a helper function, for compatibility with node 0.10.
|
Thanks for the compliment and the quick responses. I've updated the tests. Regarding the loader bug, it seems to occur whenever the scalar is anything but trailing empty lines: |
| var CHAR_TAB = 0x09; /* Tab */ | ||
| var CHAR_LINE_FEED = 0x0A; /* LF */ | ||
| var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */ | ||
| // var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */ // unused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to keep it in any form here if it's not in use. It can be just re-added in future if needed.
|
Also Overall that's very good piece of work. Thank you, @aepsilon! @puzrin, it's good for merge. However, we need to fix that loader bug before releasing this. I'll try to look into it during next week. |
|
e0c4e4e - updated asserts use everywhere. |
Rewrote the scalar dumper with an emphasis on rigor, based on a
careful reading of the YAML 1.2 spec and testing against LibYAML.
Corrections
Block style chomping accounts for the extra newline
added by subsequent elements or at the end.
Fixes #238.
Top-level block scalars are indented.
Fixes dumper side of #221.
Folded style should be reliable now. The old dumper was not aware of
the subtle rules for more-indented lines.
More-indented lines no longer cause extra newlines to be added.
(The old dumper also had an off-by-one error that dropped
the last character from a long first word on a line.)
Fixes #215, #222. Removes #217 workaround.
Literal and folded styles can represent arbitrary "printable" strings,
including leading/trailing whitespace.
(Hopefully this improves readability for many use cases.)
NB. For the 'construct-string-types' dumper test, the strings are
dumped correctly. The test fails because a loader bug
loses a newline when using the keep "+" chomping indicator.
Additional improvements
Added test suite covering several former bugs, new edge cases,
and new expected behaviors. All previous applicable tests are included.
Styles are chosen in a well-defined order.
(if enabled) and does not begin with a space.
Plain style is relaxed to include more characters and strings.
Progress on #183.
As indent increases, line width decreases down to min(lineWidth, 40).
Setting lineWidth to -1 disables wrapping.
Previously there was unexpected behavior past 40 indent:
narrow lineWidth suddenly jumped to 40,
and -1 (no limit) suddenly enforced a limit of 40.