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

v3: FoldedStyle yaml.Node results in unexpected newlines #804

Open
janakerman opened this issue Dec 10, 2021 · 0 comments · May be fixed by #960
Open

v3: FoldedStyle yaml.Node results in unexpected newlines #804

janakerman opened this issue Dec 10, 2021 · 0 comments · May be fixed by #960

Comments

@janakerman
Copy link

janakerman commented Dec 10, 2021

When Marshalling/Encoding a scalar YAML node with the folded multi-line style I see an unexpected new line in the encoded YAML.

I've added some test cases in a branch in my fork.

A yaml.Node with style.Folded and the following Value:

foo
    bar

Is marshalled with a newline between foo and bar:

>-
    foo

        bar

I'm expecting it to be marshalled as follows:

>-
    foo
        bar

Reading the spec I believe my expectations are correct.

Lines starting with white space characters (more-indented lines) are not folded.

The snippet Example 8.10. Folded Lines shows an indented line and it does not include the additional newline.

The impact of this is that marshalling unmarshalling a YAML string into a YAML node and back into a string again does not result in the same string value within the node.

gs-opensource-bot pushed a commit to goldmansachs/yaml that referenced this issue Mar 20, 2023
When using:

 >-
   someline
     more

The encoder would emit:

 >-
   someline

     more

The issue was introduced in the original translation from C to
Go. In the C code the MOVE macro would advance the start pointer
of the string. In the Go case "k = 0" points to the start of the
string where in the C case it would be the read pointer. Fix it.

Also address bound checks to not go beyond the string (I assume in
the C code there is an explicit NUL or at least some NUL).

Fixes: go-yaml#804
zecke pushed a commit to zecke/go-yaml that referenced this issue May 3, 2023
When using:

 >-
   someline
     more

The encoder would emit:

 >-
   someline

     more

The issue was introduced in the original translation from C to
Go. In the C code the MOVE macro would advance the start pointer
of the string. In the Go case "k = 0" points to the start of the
string where in the C case it would be the read pointer. Fix it.

Also address bound checks to not go beyond the string (I assume in
the C code there is an explicit NUL or at least some NUL).

Fixes: go-yaml#804
@zecke zecke linked a pull request May 3, 2023 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant