Skip to content

Commit

Permalink
Fixed a case where JSON would fail to parse if a string containing a …
Browse files Browse the repository at this point in the history
…number also contained escaped quotes.

Fixes #141.
  • Loading branch information
bhollis committed Jan 13, 2017
1 parent de15259 commit 758a9c3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 11 additions & 1 deletion lib/jsonview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "[email protected]",
"version": "1.2.1",
"version": "1.2.2",
"name": "jsonview",
"title": "JSONView",
"description": "View JSON documents in the browser.",
Expand Down
1 change: 1 addition & 0 deletions tests/issue141.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "value":[ { "@some.text":"W/\"12241774\"" } ] }
1 change: 1 addition & 0 deletions tests/issue141b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "12\"":"W/\"12241774\"" }

0 comments on commit 758a9c3

Please sign in to comment.