Skip to content
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

Extra new line added #221

Closed
IvanGoncharov opened this issue Nov 22, 2015 · 5 comments
Closed

Extra new line added #221

IvanGoncharov opened this issue Nov 22, 2015 · 5 comments
Labels

Comments

@IvanGoncharov
Copy link
Contributor

Test:

var YAML = require('js-yaml');

data = "test1\ntest2"
console.log(data);
console.log('===============================================================');
data = YAML.safeDump(data);
console.log(data);
console.log('===============================================================');
data = YAML.safeLoad(data);
console.log(data);
console.log('===============================================================');

Output:

$ node test.js 
test1
test2
===============================================================
|-
test1
test2

===============================================================
test1
test2

===============================================================

So extra new line added in the end of string.

@puzrin
Copy link
Member

puzrin commented Nov 22, 2015

Dupe?

@IvanGoncharov
Copy link
Contributor Author

@puzrin If you ask about #222, then no. It's about trailing new line and not related to 80 symbols.

@puzrin
Copy link
Member

puzrin commented Nov 23, 2015

Probably, that's because of #125 workaround (the same exists in Ruby's parser).

dervus added a commit that referenced this issue Jan 10, 2016
@dervus
Copy link
Collaborator

dervus commented Jan 10, 2016

Both this and #222 actually caused by combination of two different bugs: one in the loader, and another in the dumper.

Loader bug:

  • It doesn't throw an error on block scalar without indentation. Block scalars cannot have 0-level indentation.

Dumper bug:

  • It doesn't add indentation for top-level block scalar.

@dervus dervus added the bug label Jan 10, 2016
aepsilon added a commit to aepsilon/js-yaml that referenced this issue Mar 31, 2016
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.
@dervus
Copy link
Collaborator

dervus commented Apr 15, 2016

Dumper part if fixed by #274.

I've created separate issue for the loader bug: #280

@dervus dervus closed this as completed Apr 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants