json: support \n
This commit is contained in:
parent
f65d314d58
commit
8a779f6e41
@ -34,6 +34,16 @@ func TestDecode_interface(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"multiline_bad.hcl",
|
||||
false,
|
||||
map[string]interface{}{"foo": "bar\nbaz"},
|
||||
},
|
||||
{
|
||||
"multiline.json",
|
||||
false,
|
||||
map[string]interface{}{"foo": "bar\nbaz"},
|
||||
},
|
||||
{
|
||||
"scientific.json",
|
||||
false,
|
||||
|
12
json/lex.go
12
json/lex.go
@ -126,8 +126,16 @@ func (x *jsonLex) lexString(yylval *jsonSymType) int {
|
||||
}
|
||||
|
||||
// If we're escaping a quote, then escape the quote
|
||||
if c == '\\' && x.peek() == '"' {
|
||||
c = x.next()
|
||||
if c == '\\' {
|
||||
n := x.next()
|
||||
switch n {
|
||||
case '"':
|
||||
c = n
|
||||
case 'n':
|
||||
c = '\n'
|
||||
default:
|
||||
x.backup()
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
|
3
test-fixtures/multiline.json
Normal file
3
test-fixtures/multiline.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"foo": "bar\nbaz"
|
||||
}
|
2
test-fixtures/multiline_bad.hcl
Normal file
2
test-fixtures/multiline_bad.hcl
Normal file
@ -0,0 +1,2 @@
|
||||
foo = "bar
|
||||
baz"
|
Loading…
Reference in New Issue
Block a user