Some more fixes in `parseJS`
This commit is contained in:
parent
fada177c4a
commit
8ca4c75326
|
@ -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
|
||||||
|
|
|
@ -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,12 +57,10 @@ 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('\\');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
chars.push(c);
|
chars.push(c);
|
||||||
i++;
|
i++;
|
||||||
|
|
Loading…
Reference in New Issue