js/src/tests/ecma_3/RegExp/regress-188206.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-188206.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,185 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + *
    1.11 + * Date:    21 January 2003
    1.12 + * SUMMARY: Invalid use of regexp quantifiers should generate SyntaxErrors
    1.13 + *
    1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206
    1.15 + * and http://bugzilla.mozilla.org/show_bug.cgi?id=85721#c48 etc.
    1.16 + * and http://bugzilla.mozilla.org/show_bug.cgi?id=190685
    1.17 + * and http://bugzilla.mozilla.org/show_bug.cgi?id=197451
    1.18 + */
    1.19 +//-----------------------------------------------------------------------------
    1.20 +var UBound = 0;
    1.21 +var BUGNUMBER = 188206;
    1.22 +var summary = 'Invalid use of regexp quantifiers should generate SyntaxErrors';
    1.23 +var TEST_PASSED = 'SyntaxError';
    1.24 +var TEST_FAILED = 'Generated an error, but NOT a SyntaxError!';
    1.25 +var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
    1.26 +var CHECK_PASSED = 'Should not generate an error';
    1.27 +var CHECK_FAILED = 'Generated an error!';
    1.28 +var status = '';
    1.29 +var statusitems = [];
    1.30 +var actual = '';
    1.31 +var actualvalues = [];
    1.32 +var expect= '';
    1.33 +var expectedvalues = [];
    1.34 +
    1.35 +
    1.36 +/*
    1.37 + * All the following are invalid uses of regexp quantifiers and
    1.38 + * should generate SyntaxErrors. That's what we're testing for.
    1.39 + *
    1.40 + * To allow the test to compile and run, we have to hide the errors
    1.41 + * inside eval strings, and check they are caught at run-time -
    1.42 + *
    1.43 + */
    1.44 +status = inSection(1);
    1.45 +testThis(' /a**/ ');
    1.46 +
    1.47 +status = inSection(2);
    1.48 +testThis(' /a***/ ');
    1.49 +
    1.50 +status = inSection(3);
    1.51 +testThis(' /a++/ ');
    1.52 +
    1.53 +status = inSection(4);
    1.54 +testThis(' /a+++/ ');
    1.55 +
    1.56 +/*
    1.57 + * The ? quantifier, unlike * or +, may appear twice in succession.
    1.58 + * Thus we need at least three in a row to provoke a SyntaxError -
    1.59 + */
    1.60 +
    1.61 +status = inSection(5);
    1.62 +testThis(' /a???/ ');
    1.63 +
    1.64 +status = inSection(6);
    1.65 +testThis(' /a????/ ');
    1.66 +
    1.67 +
    1.68 +/*
    1.69 + * Now do some weird things on the left side of the regexps -
    1.70 + */
    1.71 +status = inSection(9);
    1.72 +testThis(' /+a/ ');
    1.73 +
    1.74 +status = inSection(10);
    1.75 +testThis(' /++a/ ');
    1.76 +
    1.77 +status = inSection(11);
    1.78 +testThis(' /?a/ ');
    1.79 +
    1.80 +status = inSection(12);
    1.81 +testThis(' /??a/ ');
    1.82 +
    1.83 +
    1.84 +/*
    1.85 + * Misusing the {DecmalDigits} quantifier - according to BOTH ECMA and Perl.
    1.86 + *
    1.87 + * Just as with the * and + quantifiers above, can't have two {DecmalDigits}
    1.88 + * quantifiers in succession - it's a SyntaxError.
    1.89 + */
    1.90 +status = inSection(28);
    1.91 +testThis(' /x{1}{1}/ ');
    1.92 +
    1.93 +status = inSection(29);
    1.94 +testThis(' /x{1,}{1}/ ');
    1.95 +
    1.96 +status = inSection(30);
    1.97 +testThis(' /x{1,2}{1}/ ');
    1.98 +
    1.99 +status = inSection(31);
   1.100 +testThis(' /x{1}{1,}/ ');
   1.101 +
   1.102 +status = inSection(32);
   1.103 +testThis(' /x{1,}{1,}/ ');
   1.104 +
   1.105 +status = inSection(33);
   1.106 +testThis(' /x{1,2}{1,}/ ');
   1.107 +
   1.108 +status = inSection(34);
   1.109 +testThis(' /x{1}{1,2}/ ');
   1.110 +
   1.111 +status = inSection(35);
   1.112 +testThis(' /x{1,}{1,2}/ ');
   1.113 +
   1.114 +status = inSection(36);
   1.115 +testThis(' /x{1,2}{1,2}/ ');
   1.116 +
   1.117 +
   1.118 +
   1.119 +//-----------------------------------------------------------------------------
   1.120 +test();
   1.121 +//-----------------------------------------------------------------------------
   1.122 +
   1.123 +
   1.124 +
   1.125 +/*
   1.126 + * Invalid syntax should generate a SyntaxError
   1.127 + */
   1.128 +function testThis(sInvalidSyntax)
   1.129 +{
   1.130 +  expect = TEST_PASSED;
   1.131 +  actual = TEST_FAILED_BADLY;
   1.132 +
   1.133 +  try
   1.134 +  {
   1.135 +    eval(sInvalidSyntax);
   1.136 +  }
   1.137 +  catch(e)
   1.138 +  {
   1.139 +    if (e instanceof SyntaxError)
   1.140 +      actual = TEST_PASSED;
   1.141 +    else
   1.142 +      actual = TEST_FAILED;
   1.143 +  }
   1.144 +
   1.145 +  statusitems[UBound] = status;
   1.146 +  expectedvalues[UBound] = expect;
   1.147 +  actualvalues[UBound] = actual;
   1.148 +  UBound++;
   1.149 +}
   1.150 +
   1.151 +
   1.152 +/*
   1.153 + * Allowed syntax shouldn't generate any errors
   1.154 + */
   1.155 +function checkThis(sAllowedSyntax)
   1.156 +{
   1.157 +  expect = CHECK_PASSED;
   1.158 +  actual = CHECK_PASSED;
   1.159 +
   1.160 +  try
   1.161 +  {
   1.162 +    eval(sAllowedSyntax);
   1.163 +  }
   1.164 +  catch(e)
   1.165 +  {
   1.166 +    actual = CHECK_FAILED;
   1.167 +  }
   1.168 +
   1.169 +  statusitems[UBound] = status;
   1.170 +  expectedvalues[UBound] = expect;
   1.171 +  actualvalues[UBound] = actual;
   1.172 +  UBound++;
   1.173 +}
   1.174 +
   1.175 +
   1.176 +function test()
   1.177 +{
   1.178 +  enterFunc('test');
   1.179 +  printBugNumber(BUGNUMBER);
   1.180 +  printStatus(summary);
   1.181 +
   1.182 +  for (var i=0; i<UBound; i++)
   1.183 +  {
   1.184 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.185 +  }
   1.186 +
   1.187 +  exitFunc ('test');
   1.188 +}

mercurial