• Iain Ireland's avatar
    [regexp] Fix and unify non-unicode case-folding algorithms · 3fab9d05
    Iain Ireland authored
    Non-unicode, case-insensitive regexps (e.g. /foo/i, not foo/iu) use a
    case-folding algorithm that doesn't quite match the Unicode
    definition. There are two places in irregexp that need to do
    case-folding. Prior to this patch, neither of them quite matched the
    spec (https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch).
    
    This patch implements the "Canonicalize" algorithm in
    src/regexp/special-case.h, and uses it in the relevant places. It
    replaces special-case logic around upper-casing / ASCII characters
    with the following approach:
    
    1. For most characters, calling UnicodeSet::closeOver on a set
       containing that character will produce the correct set of
       case-insensitive matches.
    
    2. For a small handful of characters (like the sharp S that prompted
       this change), UnicodeSet::closeOver will include some characters
       that should be omitted. For example, although closeOver('ß') =
       "ßẞ", uppercase('ß') is "SS", so step 3.e means that 'ß'
       canonicalizes to itself, and should not match 'ẞ'. In these cases,
       we can skip the closeOver entirely, because it will never add an
       equivalent character. These characters are in the IgnoreSet.
    
    3. For an even smaller handful of characters, UnicodeSet::closeOver
       will produce some characters that should be omitted, but also some
       characters that should be included. For example, closeOver('k') =
       "kKK" (lowercase k, uppercase K, U+212A KELVIN SIGN), but KELVIN
       SIGN should not match either of the other two (step 3.g). To handle
       this, we put such characters in the SpecialAddSet. In these cases,
       we closeOver the original character, but filter out the results
       that do not have the same canonical value.
    
    The computation of IgnoreSet and SpecialAddSet happens at build time,
    using the pre-existing gen-regexp-special-case.cc step.
    
    R=jgruber@chromium.org
    
    Bug: v8:10248
    Change-Id: I00d48b180c83bb8e645cc59eda57b01eab134f0b
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2072858Reviewed-by: 's avatarFrank Tang <ftang@chromium.org>
    Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
    Commit-Queue: Jakob Gruber <jgruber@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#66641}
    3fab9d05
Name
Last commit
Last update
..
bigint Loading commit data...
break-iterator Loading commit data...
collator Loading commit data...
date-format Loading commit data...
displaynames Loading commit data...
general Loading commit data...
list-format Loading commit data...
locale Loading commit data...
number-format Loading commit data...
overrides Loading commit data...
plural-rules Loading commit data...
relative-time-format Loading commit data...
segmenter Loading commit data...
string Loading commit data...
BUILD.gn Loading commit data...
OWNERS Loading commit data...
assert.js Loading commit data...
bad-target.js Loading commit data...
default_locale.js Loading commit data...
intl.status Loading commit data...
not-constructors.js Loading commit data...
regress-1003748.js Loading commit data...
regress-1012579.js Loading commit data...
regress-10248.js Loading commit data...
regress-1030160.js Loading commit data...
regress-1041319.js Loading commit data...
regress-4870.js Loading commit data...
regress-5179.js Loading commit data...
regress-527926.js Loading commit data...
regress-7481.js Loading commit data...
regress-7770.js Loading commit data...
regress-7982.js Loading commit data...
regress-8030.js Loading commit data...
regress-8031.js Loading commit data...
regress-8348.js Loading commit data...
regress-8432.js Loading commit data...
regress-8469.js Loading commit data...
regress-8525.js Loading commit data...
regress-8604.js Loading commit data...
regress-8657.js Loading commit data...
regress-8725514.js Loading commit data...
regress-875643.js Loading commit data...
regress-8866.js Loading commit data...
regress-888299.js Loading commit data...
regress-895942.js Loading commit data...
regress-900013.js Loading commit data...
regress-9035.js Loading commit data...
regress-903566.js Loading commit data...
regress-917151.js Loading commit data...
regress-925216.js Loading commit data...
regress-928068.js Loading commit data...
regress-930304.js Loading commit data...
regress-9312.js Loading commit data...
regress-9356.js Loading commit data...
regress-9408.js Loading commit data...
regress-9464.js Loading commit data...
regress-9475.js Loading commit data...
regress-9513.js Loading commit data...
regress-9642.js Loading commit data...
regress-966285.js Loading commit data...
regress-971636.js Loading commit data...
regress-9731.js Loading commit data...
regress-9747.js Loading commit data...
regress-9786.js Loading commit data...
regress-9787.js Loading commit data...
regress-9788.js Loading commit data...
regress-9812.js Loading commit data...
regress-9849.js Loading commit data...
regress-9887.js Loading commit data...
regress-9912.js Loading commit data...
regress-992694.js Loading commit data...
regress-997401.js Loading commit data...
testcfg.py Loading commit data...
toStringTag.js Loading commit data...
utils.js Loading commit data...