regress-119909.js (1552B)
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 * 8 * Date: 14 Jan 2002 9 * SUMMARY: Shouldn't crash on regexps with many nested parentheses 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=119909 11 * 12 */ 13 //----------------------------------------------------------------------------- 14 var BUGNUMBER = 119909; 15 var summary = "Shouldn't crash on regexps with many nested parentheses"; 16 var NO_BACKREFS = false; 17 var DO_BACKREFS = true; 18 19 20 //-------------------------------------------------- 21 test(); 22 //-------------------------------------------------- 23 24 25 function test() 26 { 27 printBugNumber(BUGNUMBER); 28 printStatus(summary); 29 30 testThis(500, NO_BACKREFS, 'hello', 'goodbye'); 31 testThis(500, DO_BACKREFS, 'hello', 'goodbye'); 32 33 reportCompare('No Crash', 'No Crash', ''); 34 } 35 36 37 /* 38 * Creates a regexp pattern like (((((((((hello))))))))) 39 * and tests str.search(), str.match(), str.replace() 40 */ 41 function testThis(numParens, doBackRefs, strOriginal, strReplace) 42 { 43 var openParen = doBackRefs? '(' : '(?:'; 44 var closeParen = ')'; 45 var pattern = ''; 46 47 for (var i=0; i<numParens; i++) {pattern += openParen;} 48 pattern += strOriginal; 49 for (i=0; i<numParens; i++) {pattern += closeParen;} 50 var re = new RegExp(pattern); 51 52 var res = strOriginal.search(re); 53 res = strOriginal.match(re); 54 res = strOriginal.replace(re, strReplace); 55 }