From f4c9e06bdcd91ce09303d24b93ef1f22a19d3f3e Mon Sep 17 00:00:00 2001 From: Toshiaki Nakatsu Date: Wed, 25 Oct 2017 17:51:19 +0900 Subject: [PATCH] fixed unescapeString in the same manner as google chrome. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trailing space is unicode terminator, to be deleted. 'hei\DF en' -> 'heißen' 'hei\00DF en' -> 'heißen' 'hei\0000DF en' -> 'heißen' Six characters of the unicode without terminator. 'hei\0000DFen' -> 'heißen' Non hex-character is unicode terminator, to be passed. 'hei\DFt' -> 'heißt' --- lib/parseValues.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/parseValues.js b/lib/parseValues.js index 97be01b..e8b1cf6 100644 --- a/lib/parseValues.js +++ b/lib/parseValues.js @@ -23,11 +23,7 @@ function endSpacingMatch(match) { } function unescapeString(content) { - return content.replace(/\\(?:([a-fA-F0-9]{1,6})|(.))/g, function(all, unicode, otherCharacter) { - if (otherCharacter) { - return otherCharacter; - } - + function conv(all, unicode) { var C = parseInt(unicode, 16); if(C < 0x10000) { return String.fromCharCode(C); @@ -35,7 +31,14 @@ function unescapeString(content) { return String.fromCharCode(Math.floor((C - 0x10000) / 0x400) + 0xD800) + String.fromCharCode((C - 0x10000) % 0x400 + 0xDC00); } - }); + } + + return content + .replace(/\\([A-F0-9]{1,6}) /gi, conv) + .replace(/\\([A-F0-9]{6})/gi, conv) + .replace(/\\([A-F0-9]{1,5})(?![A-F0-9])/gi, conv) + .replace(/\\(.)/g, "$1") + ; } function stringMatch(match, content) {