tor-browser

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

regress-179524.js (6818B)


      1 // |reftest| skip-if(!xulRuntime.shell)
      2 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /*
      8 *
      9 * Date:    11 Nov 2002
     10 * SUMMARY: JS shouldn't crash on extraneous args to str.match(), etc.
     11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=179524
     12 *
     13 * Note that when testing str.replace(), we have to be careful if the first
     14 * argument provided to str.replace() is not a regexp object. ECMA-262 says
     15 * it is NOT converted to one, unlike the case for str.match(), str.search().
     16 *
     17 * See http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21. This means
     18 * we have to be careful how we test meta-characters in the first argument
     19 * to str.replace(), if that argument is a string -
     20 */
     21 //-----------------------------------------------------------------------------
     22 var UBound = 0;
     23 var BUGNUMBER = 179524;
     24 var summary = "Don't crash on extraneous arguments to str.match(), etc.";
     25 var status = '';
     26 var statusitems = [];
     27 var actual = '';
     28 var actualvalues = [];
     29 var expect= '';
     30 var expectedvalues = [];
     31 
     32 str = 'ABC abc';
     33 var re = /z/ig;
     34 
     35 status = inSection(1);
     36 actual = str.match(re);
     37 expect = null;
     38 addThis();
     39 
     40 status = inSection(2);
     41 actual = str.match(re, 'i');
     42 expect = null;
     43 addThis();
     44 
     45 status = inSection(3);
     46 actual = str.match(re, 'g', '');
     47 expect = null;
     48 addThis();
     49 
     50 status = inSection(4);
     51 actual = str.match(re, 'z', new Object(), new Date());
     52 expect = null;
     53 addThis();
     54 
     55 
     56 /*
     57 * Now try the same thing with str.search()
     58 */
     59 status = inSection(5);
     60 actual = str.search(re);
     61 expect = -1;
     62 addThis();
     63 
     64 status = inSection(6);
     65 actual = str.search(re, 'i');
     66 expect = -1;
     67 addThis();
     68 
     69 status = inSection(7);
     70 actual = str.search(re, 'g', '');
     71 expect = -1;
     72 addThis();
     73 
     74 status = inSection(8);
     75 actual = str.search(re, 'z', new Object(), new Date());
     76 expect = -1;
     77 addThis();
     78 
     79 
     80 /*
     81 * Now try the same thing with str.replace()
     82 */
     83 status = inSection(9);
     84 actual = str.replace(re, 'Z');
     85 expect = str;
     86 addThis();
     87 
     88 status = inSection(10);
     89 actual = str.replace(re, 'Z', 'i');
     90 expect = str;
     91 addThis();
     92 
     93 status = inSection(11);
     94 actual = str.replace(re, 'Z', 'g', '');
     95 expect = str;
     96 addThis();
     97 
     98 status = inSection(12);
     99 actual = str.replace(re, 'Z', 'z', new Object(), new Date());
    100 expect = str;
    101 addThis();
    102 
    103 
    104 
    105 /*
    106 * Now test the case where str.match()'s first argument is not a regexp object.
    107 * In that case, JS follows ECMA-262 Ed.3 by converting the 1st argument to a
    108 * regexp object using the argument as a regexp pattern, but then extends ECMA
    109 * by taking any optional 2nd argument to be a regexp flag string (e.g.'ig').
    110 *
    111 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c10
    112 */
    113 status = inSection(13);
    114 actual = str.match('a').toString();
    115 expect = str.match(/a/).toString();
    116 addThis();
    117 
    118 status = inSection(14);
    119 actual = str.match('a', 'i').toString();
    120 expect = str.match(/a/).toString();
    121 addThis();
    122 
    123 status = inSection(15);
    124 actual = str.match('a', 'ig').toString();
    125 expect = str.match(/a/).toString();
    126 addThis();
    127 
    128 status = inSection(16);
    129 actual = str.match('\\s', 'm').toString();
    130 expect = str.match(/\s/).toString();
    131 addThis();
    132 
    133 
    134 /*
    135 * Now try the previous three cases with extraneous parameters
    136 */
    137 status = inSection(17);
    138 actual = str.match('a', 'i', 'g').toString();
    139 expect = str.match(/a/).toString();
    140 addThis();
    141 
    142 status = inSection(18);
    143 actual = str.match('a', 'ig', new Object()).toString();
    144 expect = str.match(/a/).toString();
    145 addThis();
    146 
    147 status = inSection(19);
    148 actual = str.match('\\s', 'm', 999).toString();
    149 expect = str.match(/\s/).toString();
    150 addThis();
    151 
    152 status = inSection(20);
    153 actual = str.match('a', 'z').toString();
    154 expect = str.match(/a/).toString();
    155 addThis();
    156 
    157 
    158 
    159 /*
    160 * Now test str.search() where the first argument is not a regexp object.
    161 * The same considerations as above apply -
    162 *
    163 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
    164 */
    165 status = inSection(21);
    166 actual = str.search('a');
    167 expect = str.search(/a/);
    168 addThis();
    169 
    170 status = inSection(22);
    171 actual = str.search('a', 'i');
    172 expect = str.search(/a/);
    173 addThis();
    174 
    175 status = inSection(23);
    176 actual = str.search('a', 'ig');
    177 expect = str.search(/a/);
    178 addThis();
    179 
    180 status = inSection(24);
    181 actual = str.search('\\s', 'm');
    182 expect = str.search(/\s/);
    183 addThis();
    184 
    185 
    186 /*
    187 * Now try the previous three cases with extraneous parameters
    188 */
    189 status = inSection(25);
    190 actual = str.search('a', 'i', 'g');
    191 expect = str.search(/a/);
    192 addThis();
    193 
    194 status = inSection(26);
    195 actual = str.search('a', 'ig', new Object());
    196 expect = str.search(/a/);
    197 addThis();
    198 
    199 status = inSection(27);
    200 actual = str.search('\\s', 'm', 999);
    201 expect = str.search(/\s/);
    202 addThis();
    203 
    204 status = inSection(28);
    205 actual = str.search('a', 'z');
    206 expect = str.search(/a/);
    207 addThis();
    208 
    209 
    210 
    211 /*
    212 * Now test str.replace() where the first argument is not a regexp object.
    213 * The same considerations as above apply, EXCEPT for meta-characters.
    214 * See introduction to testcase above. References:
    215 *
    216 * http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
    217 * http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21
    218 */
    219 status = inSection(29);
    220 actual = str.replace('a', 'Z');
    221 expect = str.replace(/a/, 'Z');
    222 addThis();
    223 
    224 status = inSection(30);
    225 actual = str.replace('a', 'Z', 'i');
    226 expect = str.replace(/a/, 'Z');
    227 addThis();
    228 
    229 status = inSection(31);
    230 actual = str.replace('a', 'Z', 'ig');
    231 expect = str.replace(/a/, 'Z');
    232 addThis();
    233 
    234 status = inSection(32);
    235 actual = str.replace('\\s', 'Z', 'm'); //<--- NO!!! No meta-characters 1st arg!
    236 actual = str.replace(' ', 'Z', 'm');   //<--- Have to do this instead
    237 expect = str.replace(/\s/, 'Z');
    238 addThis();
    239 
    240 
    241 /*
    242 * Now try the previous three cases with extraneous parameters
    243 */
    244 status = inSection(33);
    245 actual = str.replace('a', 'Z', 'i', 'g');
    246 expect = str.replace(/a/, 'Z');
    247 addThis();
    248 
    249 status = inSection(34);
    250 actual = str.replace('a', 'Z', 'ig', new Object());
    251 expect = str.replace(/a/, 'Z');
    252 addThis();
    253 
    254 status = inSection(35);
    255 actual = str.replace('\\s', 'Z', 'm', 999); //<--- NO meta-characters 1st arg!
    256 actual = str.replace(' ', 'Z', 'm', 999);   //<--- Have to do this instead
    257 expect = str.replace(/\s/, 'Z');
    258 addThis();
    259 
    260 status = inSection(36);
    261 actual = str.replace('a', 'Z', 'z');
    262 expect = str.replace(/a/, 'Z');
    263 addThis();
    264 
    265 
    266 
    267 
    268 //-----------------------------------------------------------------------------
    269 test();
    270 //-----------------------------------------------------------------------------
    271 
    272 
    273 
    274 function addThis()
    275 {
    276  statusitems[UBound] = status;
    277  actualvalues[UBound] = actual;
    278  expectedvalues[UBound] = expect;
    279  UBound++;
    280 }
    281 
    282 
    283 function test()
    284 {
    285  printBugNumber(BUGNUMBER);
    286  printStatus(summary);
    287 
    288  for (var i=0; i<UBound; i++)
    289  {
    290    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    291  }
    292 }