Skip to content

Commit

Permalink
Merge pull request #113 from goccy/feature/fix-crlf-in-double-quote
Browse files Browse the repository at this point in the history
Fix new line character in string surrounded by double quote
  • Loading branch information
goccy authored Jun 2, 2020
2 parents aefe2e5 + 1ee2aed commit 6280ab6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestParser(t *testing.T) {
"v:\n- A\n- >-\n B\n C\n",
"v: |-\n 0\n",
"v: |-\n 0\nx: 0",
`"a\n1\nb"`,
}
for _, src := range sources {
fmt.Printf(src)
Expand Down
10 changes: 7 additions & 3 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (s *Scanner) scanSingleQuote(ctx *Context) (tk *token.Token, pos int) {
continue
}
tk = token.SingleQuote(string(value), string(ctx.obuf), s.pos())
pos = len([]rune(value)) + 1
pos = idx - startIndex + 1
return
}
return
Expand All @@ -237,6 +237,11 @@ func (s *Scanner) scanDoubleQuote(ctx *Context) (tk *token.Token, pos int) {
if idx+1 < size {
nextChar := src[idx+1]
switch nextChar {
case 'n':
ctx.addOriginBuf(nextChar)
value = append(value, '\n')
idx++
continue
case '"':
ctx.addOriginBuf(nextChar)
value = append(value, nextChar)
Expand All @@ -253,9 +258,8 @@ func (s *Scanner) scanDoubleQuote(ctx *Context) (tk *token.Token, pos int) {
value = append(value, c)
continue
}

tk = token.DoubleQuote(string(value), string(ctx.obuf), s.pos())
pos = len([]rune(value)) + 1
pos = idx - startIndex + 1
return
}
return
Expand Down

0 comments on commit 6280ab6

Please sign in to comment.