From 4f24c338fa276656acd1f3d32bddcd314f51c7c7 Mon Sep 17 00:00:00 2001 From: Zachary Carter Date: Sun, 27 May 2012 14:25:28 -0700 Subject: [PATCH] fix escaping bug with backslashes --- src/jsonlint.y | 2 +- test/all-tests.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/jsonlint.y b/src/jsonlint.y index f781bda..664b99e 100644 --- a/src/jsonlint.y +++ b/src/jsonlint.y @@ -12,7 +12,7 @@ JSONString : STRING - {$$ = yytext;} + {$$ = yytext.replace(/\\\\/g, "\\");} ; JSONNumber diff --git a/test/all-tests.js b/test/all-tests.js index 161c3eb..f6782bf 100644 --- a/test/all-tests.js +++ b/test/all-tests.js @@ -7,6 +7,11 @@ exports["test object"] = function () { assert.deepEqual(parser.parse(json), {"foo": "bar"}); }; +exports["test escaped backslash"] = function () { + var json = '{"foo": "\\\\"}'; + assert.deepEqual(parser.parse(json), {"foo": "\\"}); +}; + exports["test string with escaped line break"] = function () { var json = '{"foo": "bar\\nbar"}'; assert.deepEqual(parser.parse(json), {"foo": "bar\\nbar"});