Add support for multi-line double-quoted strings with CRLF line endings (#744)

This commit is contained in:
Shuhei Kitagawa 2025-05-29 06:40:14 +02:00 committed by GitHub
parent f1c23f747b
commit 680eea761f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View file

@ -468,6 +468,18 @@ func TestDecoder(t *testing.T) {
source: "'1': \"2\\r\\n3\"", source: "'1': \"2\\r\\n3\"",
value: map[interface{}]interface{}{"1": "2\r\n3"}, value: map[interface{}]interface{}{"1": "2\r\n3"},
}, },
{
source: "'1': \"a\\\nb\\\nc\"",
value: map[interface{}]interface{}{"1": "abc"},
},
{
source: "'1': \"a\\\r\nb\\\r\nc\"",
value: map[interface{}]interface{}{"1": "abc"},
},
{
source: "'1': \"a\\\rb\\\rc\"",
value: map[interface{}]interface{}{"1": "abc"},
},
{ {
source: "a: -b_c", source: "a: -b_c",

View file

@ -522,6 +522,17 @@ func (s *Scanner) scanDoubleQuote(ctx *Context) (*token.Token, error) {
s.progressLine(ctx) s.progressLine(ctx)
idx++ idx++
continue continue
case '\r':
isFirstLineChar = true
isNewLine = true
ctx.addOriginBuf(nextChar)
s.progressLine(ctx)
progress = 1
// Skip \n after \r in CRLF sequences
if idx+2 < size && src[idx+2] == '\n' {
ctx.addOriginBuf('\n')
progress = 2
}
case '\t': case '\t':
progress = 1 progress = 1
ctx.addOriginBuf(nextChar) ctx.addOriginBuf(nextChar)