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

Folded strings lose the last character if there is no trailing whitespace #433

Open
charithe opened this issue Mar 13, 2024 · 0 comments · May be fixed by #434
Open

Folded strings lose the last character if there is no trailing whitespace #433

charithe opened this issue Mar 13, 2024 · 0 comments · May be fixed by #434
Labels
bug Something isn't working

Comments

@charithe
Copy link

Describe the bug

If the last character of a folded string is the end of the file and there's nothing else following it, the parsed token's Value field doesn't contain that last character.

To Reproduce

This is a strange case. Apparently, some editors strip the line feed character from the last line of the file even if that line is not empty. I am going to illustrate it with $ to denote the invisible line feed characters (ASCII 0a).

Normally, the file contents would look like the following and foo is correctly parsed as bar.

foo: >$
  bar$

However, the following YAML file produces ba as the value of foo. Note that there's no line feed following bar. Your editor would normally add the line feed automatically so you need to remove it by running truncate -s -1 file.yaml to reproduce this.

foo: >$
  bar

Expected behavior

Folded strings should not be truncated if there's no trailing whitespace.

Version Variables

  • Go version: 1.22.1
  • go-yaml's Version: 1.11.3 and master

Additional context

I have a patch ready and can raise a PR to fix this.

@charithe charithe added the bug Something isn't working label Mar 13, 2024
charithe added a commit to charithe/go-yaml that referenced this issue Mar 13, 2024
As described in goccy#433, if the last character of a folded string is the
very last character in the file (no trailing whitespace), it's not
included the token's `Value`.

While fixing this, I also noticed that the column information for the
folded and literal strings were the end rather than the beginning. I've
(hopefully) fixed that as well.

Fixes goccy#433

Signed-off-by: Charith Ellawala <charith@cerbos.dev>
@charithe charithe linked a pull request Mar 13, 2024 that will close this issue
charithe added a commit to cerbos/go-yaml that referenced this issue Apr 29, 2024
As described in goccy#433, if the last character of a folded string is the
very last character in the file (no trailing whitespace), it's not
included the token's `Value`.

While fixing this, I also noticed that the column information for the
folded and literal strings were the end rather than the beginning. I've
(hopefully) fixed that as well.

Fixes goccy#433

Signed-off-by: Charith Ellawala <charith@cerbos.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant