Debian Codegraph @

rhino/testsrc/tests/ecma_3/extensions/regress-228087.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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: 12 December 2003
9 * SUMMARY: Testing regexps with unescaped braces
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=228087
11 *
12 * Note: unbalanced, unescaped braces are not permitted by ECMA-262 Ed.3,
13 * but we decided to follow Perl and IE and allow this for compatibility.
14 *
15 * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206 and its testcase.
16 * See http://bugzilla.mozilla.org/show_bug.cgi?id=223273 and its testcase.
17 */
18 //-----------------------------------------------------------------------------
19 var gTestfile = 'regress-228087.js';
20 var i = 0;
21 var BUGNUMBER = 228087;
22 var summary = 'Testing regexps with unescaped braces';
23 var status = '';
24 var statusmessages = new Array();
25 var pattern = '';
26 var patterns = new Array();
27 var string = '';
28 var strings = new Array();
29 var actualmatch = '';
30 var actualmatches = new Array();
31 var expectedmatch = '';
32 var expectedmatches = new Array();
33 var e;
34
35
36 string = 'foo {1} foo {2} foo';
37
38 // try an example with the braces escaped
39 status = inSection(1);
40 try
41 {
42 pattern = new RegExp('\{1.*\}', 'g');
43 actualmatch = string.match(pattern);
44 }
45 catch (e)
46 {
47 pattern = 'error';
48 actualmatch = '';
49 }
50 expectedmatch = Array('{1} foo {2}');
51 addThis();
52
53 // just like Section 1, without the braces being escaped
54 status = inSection(2);
55 try
56 {
57 pattern = new RegExp('{1.*}', 'g');
58 actualmatch = string.match(pattern);
59 }
60 catch (e)
61 {
62 pattern = 'error';
63 actualmatch = '';
64 }
65 expectedmatch = Array('{1} foo {2}');
66 addThis();
67
68 // try an example with the braces escaped
69 status = inSection(3);
70 try
71 {
72 pattern = new RegExp('\{1[.!\}]*\}', 'g');
73 actualmatch = string.match(pattern);
74 }
75 catch (e)
76 {
77 pattern = 'error';
78 actualmatch = '';
79 }
80 expectedmatch = Array('{1}');
81 addThis();
82
83 // just like Section 3, without the braces being escaped
84 status = inSection(4);
85 try
86 {
87 pattern = new RegExp('{1[.!}]*}', 'g');
88 actualmatch = string.match(pattern);
89 }
90 catch (e)
91 {
92 pattern = 'error';
93 actualmatch = '';
94 }
95 expectedmatch = Array('{1}');
96 addThis();
97
98
99 string = 'abccccc{3 }c{ 3}c{3, }c{3 ,}c{3 ,4}c{3, 4}c{3,4 }de';
100
101 // use braces in a normal quantifier construct
102 status = inSection(5);
103 try
104 {
105 pattern = new RegExp('c{3}');
106 actualmatch = string.match(pattern);
107 }
108 catch (e)
109 {
110 pattern = 'error';
111 actualmatch = '';
112 }
113 expectedmatch = Array('ccc');
114 addThis();
115
116 // now disrupt the quantifer - the braces should now be interpreted literally
117 status = inSection(6);
118 try
119 {
120 pattern = new RegExp('c{3 }');
121 actualmatch = string.match(pattern);
122 }
123 catch (e)
124 {
125 pattern = 'error';
126 actualmatch = '';
127 }
128 expectedmatch = Array('c{3 }');
129 addThis();
130
131 status = inSection(7);
132 try
133 {
134 pattern = new RegExp('c{3.}');
135 actualmatch = string.match(pattern);
136 }
137 catch (e)
138 {
139 pattern = 'error';
140 actualmatch = '';
141 }
142 expectedmatch = Array('c{3 }');
143 addThis();
144
145 status = inSection(8);
146 try
147 {
148 // need to escape the \ in \s since
149 // this has been converted to a constructor call
150 // instead of a literal regexp
151 pattern = new RegExp('c{3\\s}');
152 actualmatch = string.match(pattern);
153 }
154 catch (e)
155 {
156 pattern = 'error';
157 actualmatch = '';
158 }
159 expectedmatch = Array('c{3 }');
160 addThis();
161
162 status = inSection(9);
163 try
164 {
165 pattern = new RegExp('c{3[ ]}');
166 actualmatch = string.match(pattern);
167 }
168 catch (e)
169 {
170 pattern = 'error';
171 actualmatch = '';
172 }
173 expectedmatch = Array('c{3 }');
174 addThis();
175
176 status = inSection(10);
177 try
178 {
179 pattern = new RegExp('c{ 3}');
180 actualmatch = string.match(pattern);
181 }
182 catch (e)
183 {
184 pattern = 'error';
185 actualmatch = '';
186 }
187 expectedmatch = Array('c{ 3}');
188 addThis();
189
190 // using braces in a normal quantifier construct again
191 status = inSection(11);
192 try
193 {
194 pattern = new RegExp('c{3,}');
195 actualmatch = string.match(pattern);
196 }
197 catch (e)
198 {
199 pattern = 'error';
200 actualmatch = '';
201 }
202 expectedmatch = Array('ccccc');
203 addThis();
204
205 // now disrupt it - the braces should now be interpreted literally
206 status = inSection(12);
207 try
208 {
209 pattern = new RegExp('c{3, }');
210 actualmatch = string.match(pattern);
211 }
212 catch (e)
213 {
214 pattern = 'error';
215 actualmatch = '';
216 }
217 expectedmatch = Array('c{3, }');
218 addThis();
219
220 status = inSection(13);
221 try
222 {
223 pattern = new RegExp('c{3 ,}');
224 actualmatch = string.match(pattern);
225 }
226 catch (e)
227 {
228 pattern = 'error';
229 actualmatch = '';
230 }
231 expectedmatch = Array('c{3 ,}');
232 addThis();
233
234 // using braces in a normal quantifier construct again
235 status = inSection(14);
236 try
237 {
238 pattern = new RegExp('c{3,4}');
239 actualmatch = string.match(pattern);
240 }
241 catch (e)
242 {
243 pattern = 'error';
244 actualmatch = '';
245 }
246 expectedmatch = Array('cccc');
247 addThis();
248
249 // now disrupt it - the braces should now be interpreted literally
250 status = inSection(15);
251 try
252 {
253 pattern = new RegExp('c{3 ,4}');
254 actualmatch = string.match(pattern);
255 }
256 catch (e)
257 {
258 pattern = 'error';
259 actualmatch = '';
260 }
261 expectedmatch = Array('c{3 ,4}');
262 addThis();
263
264 status = inSection(16);
265 try
266 {
267 pattern = new RegExp('c{3, 4}');
268 actualmatch = string.match(pattern);
269 }
270 catch (e)
271 {
272 pattern = 'error';
273 actualmatch = '';
274 }
275 expectedmatch = Array('c{3, 4}');
276 addThis();
277
278 status = inSection(17);
279 try
280 {
281 pattern = new RegExp('c{3,4 }');
282 actualmatch = string.match(pattern);
283 }
284 catch (e)
285 {
286 pattern = 'error';
287 actualmatch = '';
288 }
289 expectedmatch = Array('c{3,4 }');
290 addThis();
291
292
293
294
295 //-------------------------------------------------------------------------------------------------
296 test();
297 //-------------------------------------------------------------------------------------------------
298
299
300
301 function addThis()
302 {
303 statusmessages[i] = status;
304 patterns[i] = pattern;
305 strings[i] = string;
306 actualmatches[i] = actualmatch;
307 expectedmatches[i] = expectedmatch;
308 i++;
309 }
310
311
312 function test()
313 {
314 enterFunc ('test');
315 printBugNumber(BUGNUMBER);
316 printStatus (summary);
317 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
318 exitFunc ('test');
319 }