Skip to content

Commit 680eea7

Browse files
authored
Add support for multi-line double-quoted strings with CRLF line endings (#744)
1 parent f1c23f7 commit 680eea7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎decode_test.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,18 @@ func TestDecoder(t *testing.T) {
468468
source: "'1': \"2\\r\\n3\"",
469469
value: map[interface{}]interface{}{"1": "2\r\n3"},
470470
},
471+
{
472+
source: "'1': \"a\\\nb\\\nc\"",
473+
value: map[interface{}]interface{}{"1": "abc"},
474+
},
475+
{
476+
source: "'1': \"a\\\r\nb\\\r\nc\"",
477+
value: map[interface{}]interface{}{"1": "abc"},
478+
},
479+
{
480+
source: "'1': \"a\\\rb\\\rc\"",
481+
value: map[interface{}]interface{}{"1": "abc"},
482+
},
471483

472484
{
473485
source: "a: -b_c",

‎scanner/scanner.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,17 @@ func (s *Scanner) scanDoubleQuote(ctx *Context) (*token.Token, error) {
522522
s.progressLine(ctx)
523523
idx++
524524
continue
525+
case '\r':
526+
isFirstLineChar = true
527+
isNewLine = true
528+
ctx.addOriginBuf(nextChar)
529+
s.progressLine(ctx)
530+
progress = 1
531+
// Skip \n after \r in CRLF sequences
532+
if idx+2 < size && src[idx+2] == '\n' {
533+
ctx.addOriginBuf('\n')
534+
progress = 2
535+
}
525536
case '\t':
526537
progress = 1
527538
ctx.addOriginBuf(nextChar)

0 commit comments

Comments
 (0)