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

Chomped literals with multiple newlines lose a line-break after a roundtrip #963

Open
iliakap opened this issue May 23, 2023 · 2 comments
Open

Comments

@iliakap
Copy link

iliakap commented May 23, 2023

The following example demonstrates the bug, this yaml:

a: |2-


  str

after a decode-encode cycle, one newline is lost and the output is:

a: |2-

  str

after another decode-encode cycle the output would be:

a: |2-
  str

and so on...

here's a test case that demonstrates the bug:

var nodeTests = []struct {
	yaml string
	node yaml.Node
}{
	{
		// multiline literal starting with multiple newlines.
		"a: |2-\n\n\n  str\n",
		yaml.Node{
			Kind:   yaml.DocumentNode,
			Line:   1,
			Column: 1,
			Content: []*yaml.Node{{
				Kind:   yaml.MappingNode,
				Tag:    "!!map",
				Line:   1,
				Column: 1,
				Content: []*yaml.Node{{
					Kind:   yaml.ScalarNode,
					Tag:    "!!str",
					Value:  "a",
					Line:   1,
					Column: 1,
				}, {
					Kind:        yaml.ScalarNode,
					Style:       yaml.LiteralStyle,
					Tag:         "!!str",
					Value:       "\n\nstr",
					LineComment: "",
					Line:        1,
					Column:      4,
				}},
			}},
		},
	},
}
@iliakap iliakap changed the title Chomped literals with multiple newlines lose a line after roundtrip (decode-encode) Chomped literals with multiple newlines lose a line-break after a roundtrip May 23, 2023
@connesc
Copy link

connesc commented Jun 8, 2023

This looks as a major issue, as it affects the actual value of the string field, not only its aesthetic. Also, aren't non-chomped literals affected too?

@iliakap
Copy link
Author

iliakap commented Jul 27, 2023

@connesc Looks like it only affects literals with chomping, as they are handled slightly differently by the parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants