Skip to content

Commit

Permalink
Match updated spec for /\W/iu
Browse files Browse the repository at this point in the history
Per ES6, `/\W/iu` matched U+017F, U+212A, and, surprisingly, `K` and `S`.

This is no longer the case now that tc39/ecma262#525 is merged.

Ref. #8.
Ref. mathiasbynens/regexpu-fixtures@81eeb14.
  • Loading branch information
mathiasbynens committed Jun 23, 2016
1 parent 71f3fe7 commit 74308d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 4 additions & 2 deletions data/character-class-escape-sets.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ exports.UNICODE_IGNORE_CASE = new Map([
.addRange(0x30, 0x39)
.addRange(0x41, 0x5A)
.addRange(0x61, 0x7A)],
['W', regenerate(0x4B, 0x53, 0x60)
['W', regenerate(0x60)
.addRange(0x0, 0x2F)
.addRange(0x3A, 0x40)
.addRange(0x5B, 0x5E)
.addRange(0x7B, 0x10FFFF)]
.addRange(0x7B, 0x17E)
.addRange(0x180, 0x2129)
.addRange(0x212B, 0x10FFFF)]
]);
15 changes: 7 additions & 8 deletions scripts/character-class-escape-sets.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ function addCharacterClassEscape(lower, set) {
ESCAPE_CHARS[lower] = ESCAPE_CHARS_UNICODE[lower] = set;
const upper = lower.toUpperCase();
ESCAPE_CHARS[upper] = BMP_SET.clone().remove(set);
const uExcludeSet = UNICODE_SET.clone().remove(set);
ESCAPE_CHARS_UNICODE[upper] = uExcludeSet;
ESCAPE_CHARS_UNICODE[upper] = UNICODE_SET.clone().remove(set);
// Check if one or more symbols in this set fold to another one. If so,
// a copy of the set including the mapped symbols is created for use with
// regular expressions that have both the `u` and `i` flags set.
const codePoints = set.toArray();
const iuSet = regenerate();
let containsFoldingSymbols = false;
codePoints.forEach(function(codePoint) {
for (const codePoint of codePoints) {
let folded = caseFold(codePoint);
if (folded) {
containsFoldingSymbols = true;
Expand All @@ -44,13 +43,13 @@ function addCharacterClassEscape(lower, set) {
iuSet.add(folded);
}
}
});
ESCAPE_CHARS_UNICODE_IGNORE_CASE[lower] = containsFoldingSymbols ?
}
const iuLowerSet = containsFoldingSymbols ?
iuSet.clone().add(set) :
set;
ESCAPE_CHARS_UNICODE_IGNORE_CASE[upper] = containsFoldingSymbols ?
iuSet.clone().add(uExcludeSet) :
uExcludeSet;
const iuUpperSet = UNICODE_SET.clone().remove(iuLowerSet);
ESCAPE_CHARS_UNICODE_IGNORE_CASE[lower] = iuLowerSet;
ESCAPE_CHARS_UNICODE_IGNORE_CASE[upper] = iuUpperSet;
}

// Prepare a Regenerate set for every existing character class escape.
Expand Down

0 comments on commit 74308d5

Please sign in to comment.