Skip to content

Commit

Permalink
Fix, hopefully for the last time, quote escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Jan 25, 2017
1 parent 19917cb commit fa655c8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 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.4
---
* Fixed a case where JSON would fail to parse if a string containing a number was preceded by a quote that was preceded by a lot of escaped slashes, or occurred near another number.

JSONView 1.2.3
---
* Fixed a case where JSON would fail to parse if a string containing a number was preceded by a quote that was preceded by an escaped slash.
Expand Down
11 changes: 8 additions & 3 deletions lib/jsonview.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ var JSONView = Class({
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] !== '\\');
var escaped = false;
for (var lookback = i - 1; lookback >= 0; lookback--) {
if (str[lookback] === '\\') {
escaped = !escaped;
} else {
break;
}
}
if (!escaped) {
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.3",
"version": "1.2.4",
"name": "jsonview",
"title": "JSONView",
"description": "View JSON documents in the browser.",
Expand Down
3 changes: 3 additions & 0 deletions tests/issue141c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dots":"\"v4.0\" \"v4.0\""
}
3 changes: 3 additions & 0 deletions tests/issue141d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dots":"\\\"v4.0\" \\\\\\\\\\\"v4.0\""
}
6 changes: 6 additions & 0 deletions tests/issue141e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"abc": {
"value": "{\"user\":\"NN12345\"}"
},
"MM98765": {}
}

0 comments on commit fa655c8

Please sign in to comment.