diff --git a/CHANGELOG.md b/CHANGELOG.md index 7de1de6..a9c24d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +JSONView 1.2.2 +--- +* Fixed a case where JSON would fail to parse if a string containing a number also contained escaped quotes. + JSONView 1.2.1 --- * Fixed a case where JSON would fail to parse if a string contains a number and the JSON isn't indented. diff --git a/lib/jsonview.js b/lib/jsonview.js index 059760b..6ad5c18 100644 --- a/lib/jsonview.js +++ b/lib/jsonview.js @@ -102,7 +102,17 @@ var JSONView = Class({ // This has some memory of what its last state was var wasInQuotes = false; function isInsideQuotes(str) { - var inQuotes = (str.match(quoteFinder) || []).length % 2 === 1; + var inQuotes = false; + for (var i = 0; i < str.length; i++) { + if (str[i] === '"') { + var escaped = + (i > 0 && str[i - 1] === '\\') && + (i > 1 || str[i - 2] !== '\\'); + if (!escaped) { + inQuotes = !inQuotes; + } + } + } if (wasInQuotes) { inQuotes = !inQuotes; } diff --git a/package.json b/package.json index 5c0b20f..8bee704 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "id": "jsonview@brh.numbera.com", - "version": "1.2.1", + "version": "1.2.2", "name": "jsonview", "title": "JSONView", "description": "View JSON documents in the browser.", diff --git a/tests/issue141.json b/tests/issue141.json new file mode 100644 index 0000000..f83fd20 --- /dev/null +++ b/tests/issue141.json @@ -0,0 +1 @@ +{ "value":[ { "@some.text":"W/\"12241774\"" } ] } diff --git a/tests/issue141b.json b/tests/issue141b.json new file mode 100644 index 0000000..93af515 --- /dev/null +++ b/tests/issue141b.json @@ -0,0 +1 @@ +{ "12\"":"W/\"12241774\"" }