Skip to content

Commit

Permalink
fixed unescapeString in the same manner as google chrome.
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
Toshiaki Nakatsu committed Oct 25, 2017
1 parent d315d8d commit f4c9e06
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/parseValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ 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);
} else {
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) {
Expand Down

0 comments on commit f4c9e06

Please sign in to comment.