-
Notifications
You must be signed in to change notification settings - Fork 151
Flawed line wrapping for strings with newlines #529
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Wrapping of long strings does not work correctly. After a newline is encountered in the value it will no longer wrap any more content.
Further more, if the line length becomes small enough it inserts a leading newline and doesn't even wrap at the correct line length.
To Reproduce
import yaml from "yaml";
const data = {
foo: "bar",
longlines:
"first line which is long enough to be wrapped to a another line\nsecond line which is long enough to be wrapped to a another line\nthird line which is long enough to be wrapped to a another line",
};
console.log(
yaml.stringify(data, {
lineWidth: 40,
}),
);
// Inserts a leading newline
console.log(
yaml.stringify(data, {
lineWidth: 20,
}),
);This will print
foo: bar
longlines: >-
first line which is long enough to be
wrapped to a another line
second line which is long enough to be wrapped to a another line
third line which is long enough to be wrapped to a another line
foo: bar
longlines: >-
first line which
is long enough to be
wrapped to a another
line
second line which is long enough to be wrapped to a another line
third line which is long enough to be wrapped to a another line
Expected behaviour
foo: bar
longlines: >-
first line which is long enough to be
wrapped to a another line
second line which is long enough to
be wrapped to a another line
third line which is long enough to be
wrapped to a another line
foo: bar
longlines: >-
first line which
is long enough
to be wrapped to
a another line
second line which
is long enough to
be wrapped to a
another line
third line which
is long enough to
be wrapped to a
another line
Versions (please complete the following information):
- Environment: Node.js v18.17.0
yaml: 2.4.0
Additional context
Add any other context about the problem here.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working