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

Does not remove left side CRLF when it appears after a space character #460

Closed
mfleader opened this issue Jul 10, 2024 · 0 comments · Fixed by #462
Closed

Does not remove left side CRLF when it appears after a space character #460

mfleader opened this issue Jul 10, 2024 · 0 comments · Fixed by #462
Labels
bug Something isn't working

Comments

@mfleader
Copy link
Contributor

mfleader commented Jul 10, 2024

Describe the bug
removeLeftSideNewLineCharacter() does not remove the left side End Of Line (newline) character, \r\n, when they appear after a space. This issue does not occur in files where the EOL character is \n.

To Reproduce

package main

import (
	"fmt"
	"strings"
)

func removeLeftSideNewLineCharacter(src string) string {
	return strings.TrimLeft(
                strings.TrimLeft(strings.TrimLeft(src, "\r"), "\n"), "\r\n")
}

func existsNewLineCharacter(src string) bool {
	if strings.Index(src, "\n") > 0 {
		return true
	}
	if strings.Index(src, "\r") > 0 {
		return true
	}
	return false
}

func main() {
	input0 := fmt.Sprintf("\r\n src")
	input1 := fmt.Sprintf(" \r\n src")
	fmt.Printf("%v\n", existsNewLineCharacter(
                removeLeftSideNewLineCharacter(input0)))
	fmt.Printf("%v\n", existsNewLineCharacter(
                removeLeftSideNewLineCharacter(input1)))
}

This causes an unexpected key name error.

Expected behavior
I would expect the newline characters to be removed, so that no unexpected key name error is thrown.


Describe the bug
A second alternative is that it could instead be an issue with the tokenizer.

key1: 
  key2: abc

There is a space character after key1:. I don't know how to get a carriage return and newline character into the yaml document, so we'll imagine they are there. From viewing this document in the debugger, it appears that this space character is getting grouped with the key2 token, its Token.Origin has the value " \r\n key2". When that trailing space character after key1: is removed all of these issues are resolved. This issue does not occur in files where the EOL character is \n.

Version Variables

  • Go version: [e.g. 1.21 ]
  • go-yaml's Version: [e.g. v1.11.3 ]
@mfleader mfleader added the bug Something isn't working label Jul 10, 2024
@mfleader mfleader changed the title Does not remove left side linefeed characters when they appear after a whitespace character Does not remove left side linefeed characters when they appear after a space character Jul 10, 2024
@mfleader mfleader changed the title Does not remove left side linefeed characters when they appear after a space character Does not remove left side newline characters when they appear after a space character Jul 11, 2024
@mfleader mfleader changed the title Does not remove left side newline characters when they appear after a space character Does not remove left side CRLF when it appears after a space character Jul 11, 2024
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