diff --git a/decoder_test.go b/decoder_test.go index 75980ff..12276e2 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -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, diff --git a/json/lex.go b/json/lex.go index 0601ec1..f9be208 100644 --- a/json/lex.go +++ b/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 { diff --git a/test-fixtures/multiline.json b/test-fixtures/multiline.json new file mode 100644 index 0000000..93f7cc5 --- /dev/null +++ b/test-fixtures/multiline.json @@ -0,0 +1,3 @@ +{ + "foo": "bar\nbaz" +} diff --git a/test-fixtures/multiline_bad.hcl b/test-fixtures/multiline_bad.hcl new file mode 100644 index 0000000..7ef0cb0 --- /dev/null +++ b/test-fixtures/multiline_bad.hcl @@ -0,0 +1,2 @@ +foo = "bar +baz"