Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/regress-57631.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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: 26 November 2000
8 *
9 *
10 * SUMMARY: This test arose from Bugzilla bug 57631:
11 * "RegExp with invalid pattern or invalid flag causes segfault"
12 *
13 * Either error should throw an exception of type SyntaxError,
14 * and we check to see that it does...
15 */
16 //-----------------------------------------------------------------------------
17 var gTestfile = 'regress-57631.js';
18 var BUGNUMBER = '57631';
19 var summary = 'Testing new RegExp(pattern,flag) with illegal pattern or flag';
20 var statprefix = 'Testing for error creating illegal RegExp object on pattern ';
21 var statsuffix = 'and flag ';
22 var cnSUCCESS = 'SyntaxError';
23 var cnFAILURE = 'not a SyntaxError';
24 var singlequote = "'";
25 var i = -1; var j = -1; var s = ''; var f = '';
26 var obj = {};
27 var status = ''; var actual = ''; var expect = ''; var msg = '';
28 var legalpatterns = new Array(); var illegalpatterns = new Array();
29 var legalflags = new Array(); var illegalflags = new Array();
30
31
32 // valid regular expressions to try -
33 legalpatterns[0] = '';
34 legalpatterns[1] = 'abc';
35 legalpatterns[2] = '(.*)(3-1)\s\w';
36 legalpatterns[3] = '(.*)(...)\\s\\w';
37 legalpatterns[4] = '[^A-Za-z0-9_]';
38 legalpatterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
39
40 // invalid regular expressions to try -
41 illegalpatterns[0] = '(?)';
42 illegalpatterns[1] = '(a';
43 illegalpatterns[2] = '( ]';
44 //illegalpatterns[3] = '\d{1,s}';
45
46 // valid flags to try -
47 legalflags[0] = 'i';
48 legalflags[1] = 'g';
49 legalflags[2] = 'm';
50 legalflags[3] = undefined;
51
52 // invalid flags to try -
53 illegalflags[0] = 'a';
54 illegalflags[1] = 123;
55 illegalflags[2] = new RegExp();
56
57
58
59 //-------------------------------------------------------------------------------------------------
60 test();
61 //-------------------------------------------------------------------------------------------------
62
63
64 function test()
65 {
66 enterFunc ('test');
67 printBugNumber(BUGNUMBER);
68 printStatus (summary);
69
70 testIllegalRegExps(legalpatterns, illegalflags);
71 testIllegalRegExps(illegalpatterns, legalflags);
72 testIllegalRegExps(illegalpatterns, illegalflags);
73
74 exitFunc ('test');
75 }
76
77
78 // This function will only be called where all the patterns are illegal, or all the flags
79 function testIllegalRegExps(patterns, flags)
80 {
81 for (i in patterns)
82 {
83 s = patterns[i];
84
85 for (j in flags)
86 {
87 f = flags[j];
88 status = getStatus(s, f);
89 actual = cnFAILURE;
90 expect = cnSUCCESS;
91
92 try
93 {
94 // This should cause an exception if either s or f is illegal -
95 eval('obj = new RegExp(s, f);');
96 }
97 catch(e)
98 {
99 // We expect to get a SyntaxError - test for this:
100 if (e instanceof SyntaxError)
101 actual = cnSUCCESS;
102 }
103
104 reportCompare(expect, actual, status);
105 }
106 }
107 }
108
109
110 function getStatus(regexp, flag)
111 {
112 return (statprefix + quote(regexp) + statsuffix + quote(flag));
113 }
114
115
116 function quote(text)
117 {
118 return (singlequote + text + singlequote);
119 }