Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1496747 - Stop generating analysis for names with lone surrogates
  • Loading branch information
staktrace committed Oct 10, 2018
1 parent c6fec42 commit 189601d
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions scripts/js-analyze.js
Expand Up @@ -53,13 +53,43 @@ function locstr2(loc, str)

function nameValid(name)
{
return name &&
name.indexOf(" ") == -1 &&
name.indexOf("\n") == -1 &&
name.indexOf("\r") == -1 &&
name.indexOf("\0") == -1 &&
name.indexOf("\\") == -1 &&
name.indexOf('"') == -1;
if (!name) {
return false;
}
for (var i = 0; i < name.length; i++) {
var c = name.charCodeAt(i);
switch (c) {
case 0: // '\0'
case 10: // '\n'
case 13: // '\r'
case 32: // ' '
case 34: // '"'
case 92: // '\\'
return false;
}

// If we have a Unicode surrogate character, make sure
// it is a part of a valid surrogate pair, otherwise return false.

if (c < 0xD800) {
// Optimize common case
continue;
}
if (c <= 0xDBFF && i + 1 < name.length) {
// c is a high surrogate, check to make sure next char is a low surrogate
var d = name.charCodeAt(i + 1);
if (d >= 0xDC00 && d <= 0xDFFF) {
// valid; skip over the pair and continue
i++;
continue;
}
}
// fail on any surrogate characters that weren't part of a pair
if (c <= 0xDFFF) {
return false;
}
}
return true;
}

function memberPropLoc(expr)
Expand Down

0 comments on commit 189601d

Please sign in to comment.