diff --git a/src/js/Node.js b/src/js/Node.js index 124ca60..7f55825 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -984,6 +984,7 @@ Node.prototype._getDomValue = function(silent) { try { // retrieve the value var value; + console.log('getValue', this.valueInnerText, this.valueInnerText.length) if (this.type == 'string') { value = this._unescapeHTML(this.valueInnerText); } @@ -2857,16 +2858,13 @@ Node.prototype._stringCast = function(str) { * @private */ Node.prototype._escapeHTML = function (text) { - var htmlEscaped = String(text) + return String(text) .replace(/&/g, '&') // must be replaced first! .replace(//g, '>') .replace(/ /g, '  ') // replace double space with an nbsp and space .replace(/^ /, ' ') // space at start .replace(/ $/, ' '); // space at end - - var json = JSON.stringify(htmlEscaped); - return json.substring(1, json.length - 1); }; /** @@ -2876,13 +2874,11 @@ Node.prototype._escapeHTML = function (text) { * @private */ Node.prototype._unescapeHTML = function (escapedText) { - var json = '"' + this._escapeJSON(escapedText) + '"'; - var htmlEscaped = util.parse(json); - return htmlEscaped + return this._escapeJSON(escapedText) .replace(/</g, '<') .replace(/>/g, '>') .replace(/ |\u00A0/g, ' ') - .replace(/&/g, '&'); // must be replaced last + .replace(/&/g, '&'); // must be replaced last }; /** @@ -2897,8 +2893,8 @@ Node.prototype._unescapeHTML = function (escapedText) { Node.prototype._escapeJSON = function (text) { // TODO: replace with some smart regex (only when a new solution is faster!) var escaped = ''; - var i = 0, iMax = text.length; - while (i < iMax) { + var i = 0; + while (i < text.length) { var c = text.charAt(i); if (c == '\n') { escaped += '\\n'; @@ -2908,7 +2904,7 @@ Node.prototype._escapeJSON = function (text) { i++; c = text.charAt(i); - if ('"\\/bfnrtu'.indexOf(c) == -1) { + if (c === '' || '"\\/bfnrtu'.indexOf(c) == -1) { escaped += '\\'; // no valid escape character } escaped += c; diff --git a/test/test_build.html b/test/test_build.html index bf0d998..8abdce6 100644 --- a/test/test_build.html +++ b/test/test_build.html @@ -52,7 +52,8 @@ "array": [1, 2, 3], "boolean": true, "htmlcode": '"', - "unicode": '®', + "unicode": '\\u20b9', + "invalid": '\u20b9', "null": null, "number": 123, "object": {"a": "b", "c": "d"},