Skip to content

Commit

Permalink
Handle \r in a double-quoted string the same as \n (#372)
Browse files Browse the repository at this point in the history
* Add tests for string containing `\n` or `\r`

* Handle `\r` in a double-quoted string the same as `\n`

Fix #371
  • Loading branch information
k1LoW committed May 24, 2023
1 parent 1bbf205 commit 6a080f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions decode_test.go
Expand Up @@ -425,6 +425,14 @@ func TestDecoder(t *testing.T) {
`"1": "a\x2Fb\u002Fc\U0000002Fd"`,
map[interface{}]interface{}{"1": `a/b/c/d`},
},
{
"'1': \"2\\n3\"",
map[interface{}]interface{}{"1": "2\n3"},
},
{
"'1': \"2\\r\\n3\"",
map[interface{}]interface{}{"1": "2\r\n3"},
},

{
"a: -b_c",
Expand Down
5 changes: 5 additions & 0 deletions scanner/scanner.go
Expand Up @@ -339,6 +339,11 @@ func (s *Scanner) scanDoubleQuote(ctx *Context) (tk *token.Token, pos int) {
value = append(value, '\n')
idx++
continue
case 'r':
ctx.addOriginBuf(nextChar)
value = append(value, '\r')
idx++
continue
case 'v':
ctx.addOriginBuf(nextChar)
value = append(value, '\v')
Expand Down

0 comments on commit 6a080f2

Please sign in to comment.