summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_3/RegExp/regress-119909.js
blob: f0d3d08f0d1930f317cc121344a6512fe164d5ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
 *
 * Date:    14 Jan 2002
 * SUMMARY: Shouldn't crash on regexps with many nested parentheses
 * See http://bugzilla.mozilla.org/show_bug.cgi?id=119909
 *
 */
//-----------------------------------------------------------------------------
var BUGNUMBER = 119909;
var summary = "Shouldn't crash on regexps with many nested parentheses";
var NO_BACKREFS = false;
var DO_BACKREFS = true;


//--------------------------------------------------
test();
//--------------------------------------------------


function test()
{
  enterFunc('test');
  printBugNumber(BUGNUMBER);
  printStatus(summary);

  testThis(500, NO_BACKREFS, 'hello', 'goodbye');
  testThis(500, DO_BACKREFS, 'hello', 'goodbye');

  reportCompare('No Crash', 'No Crash', '');

  exitFunc('test');
}


/*
 * Creates a regexp pattern like (((((((((hello)))))))))
 * and tests str.search(), str.match(), str.replace()
 */
function testThis(numParens, doBackRefs, strOriginal, strReplace)
{
  var openParen = doBackRefs? '(' : '(?:';
  var closeParen = ')';
  var pattern = '';
 
  for (var i=0; i<numParens; i++) {pattern += openParen;}
  pattern += strOriginal;
  for (i=0; i<numParens; i++) {pattern += closeParen;}
  var re = new RegExp(pattern);

  var res = strOriginal.search(re);
  res = strOriginal.match(re);
  res = strOriginal.replace(re, strReplace);
}