js/src/jit-test/tests/basic/bug593663-regexp.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* 
     2  * Ensure that flat matches with metachars in them don't have their metachars
     3  * interpreted as special.
     4  */
     6 function isPatternSyntaxError(pattern) {
     7     try {
     8         new RegExp(pattern);
     9         return false;
    10     } catch (e if e instanceof SyntaxError) {
    11         return true;
    12     }
    13 }
    15 // Bug example.
    16 assertEq("1+2".replace("1+2", "$&+3", "g"), "1+2+3");
    17 assertEq("1112".replace("1+2", "", "g"), "1112");
    19 // ^
    20 assertEq("leading text^my hat".replace("^my hat", "", "g"), "leading text");
    21 assertEq("my hat".replace("^my hat", "", "g"), "my hat");
    23 // $
    24 assertEq("leading text$my money".replace("leading text$", "", "g"), "my money");
    25 assertEq("leading text".replace("leading text$", "", "g"), "leading text");
    27 // \
    28 var BSL = '\\';
    29 assertEq(("dir C:" + BSL + "Windoze").replace("C:" + BSL, "", "g"),
    30          "dir Windoze");
    31 assertEq(isPatternSyntaxError("C:" + BSL), true);
    33 // .
    34 assertEq("This is a sentence. It has words.".replace(".", "!", "g"),
    35          "This is a sentence! It has words!");
    36 assertEq("This is an unterminated sentence".replace(".", "", "g"),
    37          "This is an unterminated sentence");
    39 // *
    40 assertEq("Video killed the radio *".replace(" *", "", "g"), "Video killed the radio");
    41 assertEq("aaa".replace("a*", "", "g"), "aaa");
    43 // +
    44 assertEq("On the + side".replace(" +", "", "g"), "On the side");
    45 assertEq("1111111111111".replace("1+", "", "g"), "1111111111111");
    47 // \+
    48 assertEq(("Inverse cone head: " + BSL + "++/").replace(BSL + "+", "", "g"),
    49          "Inverse cone head: +/");
    50 assertEq((BSL + BSL + BSL).replace(BSL + "+", "", "g"),
    51          BSL + BSL + BSL);
    53 // \\+
    54 assertEq((BSL + BSL + "+").replace(BSL + BSL + "+", "", "g"), "");
    55 assertEq((BSL + BSL + BSL).replace(BSL + BSL + "+", "", "g"), (BSL + BSL + BSL));
    57 // \\\
    58 assertEq((BSL + BSL + BSL + BSL).replace(BSL + BSL + BSL, "", "g"), BSL);
    59 assertEq(isPatternSyntaxError(BSL + BSL + BSL), true);
    61 // \\\\
    62 assertEq((BSL + BSL + BSL + BSL).replace(BSL + BSL + BSL + BSL, "", "i"), "");
    63 assertEq((BSL + BSL).replace(BSL + BSL + BSL + BSL, "", "g"), BSL + BSL);
    66 // ?
    67 assertEq("Pressing question?".replace("?", ".", "g"), "Pressing question.");
    68 assertEq("a".replace("a?", "", "g"), "a");
    70 // (
    71 assertEq("(a".replace("(", "", "g"), "a");
    73 // )
    74 assertEq("a)".replace(")", "", "g"), "a");
    76 // ( and )
    77 assertEq("(foo)".replace("(foo)", "", "g"), "");
    78 assertEq("a".replace("(a)", "", "g"), "a");
    80 // [
    81 assertEq("[a".replace("[", "", "g"), "a");
    83 // ]
    84 assertEq("a]".replace("]", "", "g"), "a");
    86 // [ and ]
    87 assertEq("a".replace("[a-z]", "", "g"), "a");
    88 assertEq("You would write your regexp as [a-z]".replace("[a-z]", "", "g"),
    89          "You would write your regexp as ");
    91 // {
    92 assertEq("Numbers may be specified in the interval {1,100}".replace("{1,", "", "g"),
    93          "Numbers may be specified in the interval 100}");
    95 // }
    96 assertEq("Numbers may be specified in the interval {1,100}".replace(",100}", "", "g"),
    97          "Numbers may be specified in the interval {1");
    99 // { and }
   100 assertEq("Numbers may be specified in the interval {1,100}".replace(" {1,100}", "", "g"),
   101          "Numbers may be specified in the interval");
   102 assertEq("aaa".replace("a{1,10}", "", "g"), "aaa");
   104 // |
   105 assertEq("Mr. Gorbachev|Tear down this wall!".replace("|Tear down this wall!", "", "g"),
   106          "Mr. Gorbachev");
   107 assertEq("foobar".replace("foo|bar", "", "g"), "foobar");
   109 print("PASS");

mercurial