Some more fixes in `parseJS`

This commit is contained in:
jos 2014-08-01 09:33:00 +02:00
parent fada177c4a
commit 8ca4c75326
2 changed files with 7 additions and 6 deletions

View File

@ -5,7 +5,8 @@ https://github.com/josdejong/jsoneditor
## 2014-08-01, version 3.1.2 ## 2014-08-01, version 3.1.2
- Fixed `parseJS` not being able to parse a single quoted string to JSON. - Some fixes/improvements in `parseJS` (to parse a JSON object from a JavaScript
object).
## 2014-08-01, version 3.1.1 ## 2014-08-01, version 3.1.1

View File

@ -45,7 +45,9 @@ define(function () {
while(i < jsString.length) { while(i < jsString.length) {
var c = jsString.charAt(i); var c = jsString.charAt(i);
if (c === '"' || c === '\'') { var isEscaped = jsString.charAt(i - 1) === '\\';
if ((c === '"' || c === '\'') && !isEscaped) {
if (c === inString) { if (c === inString) {
// end of string // end of string
inString = false; inString = false;
@ -55,10 +57,8 @@ define(function () {
inString = c; inString = c;
} }
else { else {
// add escape character if not escaped // add escape character
if (jsString.charAt(i - 1) !== '\\') { chars.push('\\');
chars.push('\\');
}
} }
} }