From 8ca4c75326688ed8644d264f590d16c25588a393 Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 1 Aug 2014 09:33:00 +0200 Subject: [PATCH] Some more fixes in `parseJS` --- HISTORY.md | 3 ++- src/js/util.js | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 72f6d8a..0f891e5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,7 +5,8 @@ https://github.com/josdejong/jsoneditor ## 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 diff --git a/src/js/util.js b/src/js/util.js index fe54d44..05b55a2 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -45,7 +45,9 @@ define(function () { while(i < jsString.length) { var c = jsString.charAt(i); - if (c === '"' || c === '\'') { + var isEscaped = jsString.charAt(i - 1) === '\\'; + if ((c === '"' || c === '\'') && !isEscaped) { + if (c === inString) { // end of string inString = false; @@ -55,10 +57,8 @@ define(function () { inString = c; } else { - // add escape character if not escaped - if (jsString.charAt(i - 1) !== '\\') { - chars.push('\\'); - } + // add escape character + chars.push('\\'); } }