Skip to content

Commit

Permalink
Merge pull request #127 from goccy/feature/fix-issue118
Browse files Browse the repository at this point in the history
Fix processing of CRLF at parser
  • Loading branch information
goccy authored Jun 9, 2020
2 parents 559f2ab + 163bb3c commit afec5fb
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func (p *parser) parseTag(ctx *context) (ast.Node, error) {
}

func (p *parser) removeLeftSideNewLineCharacter(src string) string {
return strings.TrimLeft(strings.TrimLeft(src, "\r"), "\n")
// CR or LF or CRLF
return strings.TrimLeft(strings.TrimLeft(strings.TrimLeft(src, "\r"), "\n"), "\r\n")
}

func (p *parser) existsNewLineCharacter(src string) bool {
Expand Down
2 changes: 1 addition & 1 deletion parser/testdata/cr.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a: "a"b: 1
a: "a"b: 1
Expand Down
1 change: 1 addition & 0 deletions parser/testdata/crlf.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
a: "a"

b: 1
1 change: 1 addition & 0 deletions parser/testdata/lf.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
a: "a"

b: 1
4 changes: 2 additions & 2 deletions printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ func (p *Printer) PrintErrorMessage(msg string, isColored bool) string {
}

func (p *Printer) removeLeftSideNewLineChar(src string) string {
return strings.TrimLeft(strings.TrimLeft(src, "\r"), "\n")
return strings.TrimLeft(strings.TrimLeft(strings.TrimLeft(src, "\r"), "\n"), "\r\n")
}

func (p *Printer) removeRightSideNewLineChar(src string) string {
return strings.TrimRight(strings.TrimRight(src, "\r"), "\n")
return strings.TrimRight(strings.TrimRight(strings.TrimRight(src, "\r"), "\n"), "\r\n")
}

func (p *Printer) removeRightSideWhiteSpaceChar(src string) string {
Expand Down

0 comments on commit afec5fb

Please sign in to comment.