Skip to content

Commit

Permalink
Merge pull request #36 from Songmu/newline
Browse files Browse the repository at this point in the history
support CR
  • Loading branch information
goccy authored Nov 10, 2019
2 parents d5d303c + 106dca2 commit 97cdb16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,14 @@ func TestDecoder(t *testing.T) {
"hello: world\n",
map[string]string{"hello": "world"},
},
{
"hello: world\r\n",
map[string]string{"hello": "world"},
},
{
"hello: world\rGo: Gopher",
map[string]string{"hello": "world", "Go": "Gopher"},
},

// Structs and type conversions.
{
Expand Down
11 changes: 10 additions & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,16 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
pos += progress
return
}
case '\n':
case '\r', '\n':
// There is no problem that we ignore CR which followed by LF and normalize it to LF, because of following YAML1.2 spec.
// > Line breaks inside scalar content must be normalized by the YAML processor. Each such line break must be parsed into a single line feed character.
// > Outside scalar content, YAML allows any line break to be used to terminate lines.
// > -- https://yaml.org/spec/1.2/spec.html
if c == '\r' && ctx.nextChar() == '\n' {
ctx.addOriginBuf('\r')
ctx.progress(1)
c = '\n'
}
s.scanNewLine(ctx, c)
continue
case ' ':
Expand Down

0 comments on commit 97cdb16

Please sign in to comment.