tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bug576837-regexp.js (1486B)


      1 /*
      2 * Check that builtin character classes within ranges produce syntax
      3 * errors.
      4 *
      5 * Note: /\b/ is the backspace escape, which is a single pattern character,
      6 * though it looks deceptively like a character class.
      7 */
      8 
      9 function isRegExpSyntaxError(pattern) {
     10    try {
     11        var re = new RegExp(pattern);
     12    } catch (e) {
     13        if (e instanceof SyntaxError)
     14            return true;
     15    }
     16    return false;
     17 }
     18 
     19 //assertEq(isRegExpSyntaxError('[C-\\s]'), false);
     20 //assertEq(isRegExpSyntaxError('[C-\\d]'), false);
     21 //assertEq(isRegExpSyntaxError('[C-\\W]'), false);
     22 assertEq(isRegExpSyntaxError('[C-]'), false);
     23 assertEq(isRegExpSyntaxError('[-C]'), false);
     24 assertEq(isRegExpSyntaxError('[C-C]'), false);
     25 assertEq(isRegExpSyntaxError('[C-C]'), false);
     26 assertEq(isRegExpSyntaxError('[\\b-\\b]'), false);
     27 assertEq(isRegExpSyntaxError('[\\B-\\B]'), false);
     28 assertEq(isRegExpSyntaxError('[\\b-\\B]'), false);
     29 assertEq(isRegExpSyntaxError('[\\B-\\b]'), true);
     30 //assertEq(isRegExpSyntaxError('[\\b-\\w]'), false);
     31 //assertEq(isRegExpSyntaxError('[\\B-\\w]'), false);
     32 
     33 /* Extension. */
     34 assertEq(isRegExpSyntaxError('[\\s-\\s]'), false);
     35 assertEq(isRegExpSyntaxError('[\\W-\\s]'), false);
     36 assertEq(isRegExpSyntaxError('[\\s-\\W]'), false);
     37 assertEq(isRegExpSyntaxError('[\\W-C]'), false);
     38 assertEq(isRegExpSyntaxError('[\\d-C]'), false);
     39 assertEq(isRegExpSyntaxError('[\\s-C]'), false);
     40 assertEq(isRegExpSyntaxError('[\\w-\\b]'), false);
     41 assertEq(isRegExpSyntaxError('[\\w-\\B]'), false);