Skip to content

Commit 758a9c3

Browse files
committed
Fixed a case where JSON would fail to parse if a string containing a number also contained escaped quotes.
Fixes #141.
1 parent de15259 commit 758a9c3

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
JSONView 1.2.2
2+
---
3+
* Fixed a case where JSON would fail to parse if a string containing a number also contained escaped quotes.
4+
15
JSONView 1.2.1
26
---
37
* Fixed a case where JSON would fail to parse if a string contains a number and the JSON isn't indented.

lib/jsonview.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ var JSONView = Class({
102102
// This has some memory of what its last state was
103103
var wasInQuotes = false;
104104
function isInsideQuotes(str) {
105-
var inQuotes = (str.match(quoteFinder) || []).length % 2 === 1;
105+
var inQuotes = false;
106+
for (var i = 0; i < str.length; i++) {
107+
if (str[i] === '"') {
108+
var escaped =
109+
(i > 0 && str[i - 1] === '\\') &&
110+
(i > 1 || str[i - 2] !== '\\');
111+
if (!escaped) {
112+
inQuotes = !inQuotes;
113+
}
114+
}
115+
}
106116
if (wasInQuotes) {
107117
inQuotes = !inQuotes;
108118
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"name": "jsonview",
55
"title": "JSONView",
66
"description": "View JSON documents in the browser.",

tests/issue141.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "value":[ { "@some.text":"W/\"12241774\"" } ] }

tests/issue141b.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "12\"":"W/\"12241774\"" }

0 commit comments

Comments
 (0)