json: support \n

This commit is contained in:
Mitchell Hashimoto 2014-08-21 14:42:02 -07:00
parent f65d314d58
commit 8a779f6e41
4 changed files with 25 additions and 2 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -0,0 +1,3 @@
{
"foo": "bar\nbaz"
}

View File

@ -0,0 +1,2 @@
foo = "bar
baz"