tor-browser

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

regress-105972.js (3341B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 * Date: 22 October 2001
      8 *
      9 * SUMMARY: Regression test for Bugzilla bug 105972:
     10 * "/^.*?$/ will not match anything"
     11 *
     12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=105972
     13 */
     14 //-----------------------------------------------------------------------------
     15 var i = 0;
     16 var BUGNUMBER = 105972;
     17 var summary = 'Regression test for Bugzilla bug 105972';
     18 var cnEmptyString = '';
     19 var status = '';
     20 var statusmessages = new Array();
     21 var pattern = '';
     22 var patterns = new Array();
     23 var string = '';
     24 var strings = new Array();
     25 var actualmatch = '';
     26 var actualmatches = new Array();
     27 var expectedmatch = '';
     28 var expectedmatches = new Array();
     29 
     30 
     31 /*
     32 * The bug: this match was coming up null in Rhino and SpiderMonkey.
     33 * It should match the whole string. The reason:
     34 *
     35 * The * operator is greedy, but *? is non-greedy: it will stop
     36 * at the simplest match it can find. But the pattern here asks us
     37 * to match till the end of the string. So the simplest match must
     38 * go all the way out to the end, and *? has no choice but to do it.
     39 */
     40 status = inSection(1);
     41 pattern = /^.*?$/;
     42 string = 'Hello World';
     43 actualmatch = string.match(pattern);
     44 expectedmatch = Array(string);
     45 addThis();
     46 
     47 
     48 /*
     49 * Leave off the '$' condition - here we expect the empty string.
     50 * Unlike the above pattern, we don't have to match till the end of
     51 * the string, so the non-greedy operator *? doesn't try to...
     52 */
     53 status = inSection(2);
     54 pattern = /^.*?/;
     55 string = 'Hello World';
     56 actualmatch = string.match(pattern);
     57 expectedmatch = Array(cnEmptyString);
     58 addThis();
     59 
     60 
     61 /*
     62 * Try '$' combined with an 'or' operator.
     63 *
     64 * The operator *? will consume the string from left to right,
     65 * attempting to satisfy the condition (:|$). When it hits ':',
     66 * the match will stop because the operator *? is non-greedy.
     67 *
     68 * The submatch $1 = (:|$) will contain the ':'
     69 */
     70 status = inSection(3);
     71 pattern = /^.*?(:|$)/;
     72 string = 'Hello: World';
     73 actualmatch = string.match(pattern);
     74 expectedmatch = Array('Hello:', ':');
     75 addThis();
     76 
     77 
     78 /*
     79 * Again, '$' combined with an 'or' operator.
     80 *
     81 * The operator * will consume the string from left to right,
     82 * attempting to satisfy the condition (:|$). When it hits ':',
     83 * the match will not stop since * is greedy. The match will
     84 * continue until it hits $, the end-of-string boundary.
     85 *
     86 * The submatch $1 = (:|$) will contain the empty string
     87 * conceived to exist at the end-of-string boundary.
     88 */
     89 status = inSection(4);
     90 pattern = /^.*(:|$)/;
     91 string = 'Hello: World';
     92 actualmatch = string.match(pattern);
     93 expectedmatch = Array(string, cnEmptyString);
     94 addThis();
     95 
     96 
     97 
     98 
     99 //-----------------------------------------------------------------------------
    100 test();
    101 //-----------------------------------------------------------------------------
    102 
    103 
    104 
    105 function addThis()
    106 {
    107  statusmessages[i] = status;
    108  patterns[i] = pattern;
    109  strings[i] = string;
    110  actualmatches[i] = actualmatch;
    111  expectedmatches[i] = expectedmatch;
    112  i++;
    113 }
    114 
    115 
    116 function test()
    117 {
    118  printBugNumber(BUGNUMBER);
    119  printStatus (summary);
    120  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
    121 }