js/src/tests/js1_5/extensions/regress-330569.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/extensions/regress-330569.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +// |reftest| skip -- Yarr doesn't bail on complex regexps.
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +//-----------------------------------------------------------------------------
    1.11 +var BUGNUMBER = 330569;
    1.12 +var summary = 'RegExp - throw InternalError on too complex regular expressions';
    1.13 +var actual = '';
    1.14 +var expect = '';
    1.15 +
    1.16 +
    1.17 +//-----------------------------------------------------------------------------
    1.18 +test();
    1.19 +//-----------------------------------------------------------------------------
    1.20 +
    1.21 +function test()
    1.22 +{
    1.23 +  enterFunc ('test');
    1.24 +  printBugNumber(BUGNUMBER);
    1.25 +  printStatus (summary);
    1.26 + 
    1.27 +  var s;
    1.28 +  expect = 'InternalError: regular expression too complex';
    1.29 + 
    1.30 +  s = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' +
    1.31 +    '<html>\n' +
    1.32 +    '<head>\n' +
    1.33 +    '<meta http-equiv="content-type" content="text/html; charset=windows-1250">\n' +
    1.34 +    '<meta name="generator" content="PSPad editor, www.pspad.com">\n' +
    1.35 +    '<title></title>\n'+
    1.36 +    '</head>\n' +
    1.37 +    '<body>\n' +
    1.38 +    '<!-- hello -->\n' +
    1.39 +    '<script language="JavaScript">\n' +
    1.40 +    'var s = document. body. innerHTML;\n' +
    1.41 +    'var d = s. replace (/<!--(.*|\n)*-->/, "");\n' +
    1.42 +    'alert (d);\n' +
    1.43 +    '</script>\n' +
    1.44 +    '</body>\n' +
    1.45 +    '</html>\n';
    1.46 +
    1.47 +  try
    1.48 +  {
    1.49 +    /<!--(.*|\n)*-->/.exec(s);
    1.50 +  }
    1.51 +  catch(ex)
    1.52 +  {
    1.53 +    actual = ex + '';
    1.54 +  }
    1.55 +
    1.56 +  reportCompare(expect, actual, summary + ': /<!--(.*|\\n)*-->/.exec(s)');
    1.57 +
    1.58 +  function testre( re, n ) {
    1.59 +    for ( var i= 0; i <= n; ++i ) {
    1.60 +      re.test( Array( i+1 ).join() );
    1.61 +    }
    1.62 +  }
    1.63 +
    1.64 +  try
    1.65 +  {
    1.66 +    testre( /(?:,*)*x/, 22 );
    1.67 +  }
    1.68 +  catch(ex)
    1.69 +  {
    1.70 +    actual = ex + '';
    1.71 +  }
    1.72 +
    1.73 +  reportCompare(expect, actual, summary + ': testre( /(?:,*)*x/, 22 )');
    1.74 +
    1.75 +  try
    1.76 +  {
    1.77 +    testre( /(?:,|,)*x/, 22 );
    1.78 +  }
    1.79 +  catch(ex)
    1.80 +  {
    1.81 +    actual = ex + '';
    1.82 +  }
    1.83 +
    1.84 +  reportCompare(expect, actual, summary + ': testre( /(?:,|,)*x/, 22 )');
    1.85 +
    1.86 +  try
    1.87 +  {
    1.88 +    testre( /(?:,|,|,|,|,)*x/, 10 );
    1.89 +  }
    1.90 +  catch(ex)
    1.91 +  {
    1.92 +    actual = ex + '';
    1.93 +  }
    1.94 +  reportCompare(expect, actual, summary + ': testre( /(?:,|,|,|,|,)*x/, 10 )');
    1.95 +
    1.96 +  exitFunc ('test');
    1.97 +}

mercurial