1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/extensions/regress-228087.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,318 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 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: 12 December 2003 1.12 + * SUMMARY: Testing regexps with unescaped braces 1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=228087 1.14 + * 1.15 + * Note: unbalanced, unescaped braces are not permitted by ECMA-262 Ed.3, 1.16 + * but we decided to follow Perl and IE and allow this for compatibility. 1.17 + * 1.18 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206 and its testcase. 1.19 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=223273 and its testcase. 1.20 + */ 1.21 +//----------------------------------------------------------------------------- 1.22 +var i = 0; 1.23 +var BUGNUMBER = 228087; 1.24 +var summary = 'Testing regexps with unescaped braces'; 1.25 +var status = ''; 1.26 +var statusmessages = new Array(); 1.27 +var pattern = ''; 1.28 +var patterns = new Array(); 1.29 +var string = ''; 1.30 +var strings = new Array(); 1.31 +var actualmatch = ''; 1.32 +var actualmatches = new Array(); 1.33 +var expectedmatch = ''; 1.34 +var expectedmatches = new Array(); 1.35 +var e; 1.36 + 1.37 + 1.38 +string = 'foo {1} foo {2} foo'; 1.39 + 1.40 +// try an example with the braces escaped 1.41 +status = inSection(1); 1.42 +try 1.43 +{ 1.44 + pattern = new RegExp('\{1.*\}', 'g'); 1.45 + actualmatch = string.match(pattern); 1.46 +} 1.47 +catch (e) 1.48 +{ 1.49 + pattern = 'error'; 1.50 + actualmatch = ''; 1.51 +} 1.52 +expectedmatch = Array('{1} foo {2}'); 1.53 +addThis(); 1.54 + 1.55 +// just like Section 1, without the braces being escaped 1.56 +status = inSection(2); 1.57 +try 1.58 +{ 1.59 + pattern = new RegExp('{1.*}', 'g'); 1.60 + actualmatch = string.match(pattern); 1.61 +} 1.62 +catch (e) 1.63 +{ 1.64 + pattern = 'error'; 1.65 + actualmatch = ''; 1.66 +} 1.67 +expectedmatch = Array('{1} foo {2}'); 1.68 +addThis(); 1.69 + 1.70 +// try an example with the braces escaped 1.71 +status = inSection(3); 1.72 +try 1.73 +{ 1.74 + pattern = new RegExp('\{1[.!\}]*\}', 'g'); 1.75 + actualmatch = string.match(pattern); 1.76 +} 1.77 +catch (e) 1.78 +{ 1.79 + pattern = 'error'; 1.80 + actualmatch = ''; 1.81 +} 1.82 +expectedmatch = Array('{1}'); 1.83 +addThis(); 1.84 + 1.85 +// just like Section 3, without the braces being escaped 1.86 +status = inSection(4); 1.87 +try 1.88 +{ 1.89 + pattern = new RegExp('{1[.!}]*}', 'g'); 1.90 + actualmatch = string.match(pattern); 1.91 +} 1.92 +catch (e) 1.93 +{ 1.94 + pattern = 'error'; 1.95 + actualmatch = ''; 1.96 +} 1.97 +expectedmatch = Array('{1}'); 1.98 +addThis(); 1.99 + 1.100 + 1.101 +string = 'abccccc{3 }c{ 3}c{3, }c{3 ,}c{3 ,4}c{3, 4}c{3,4 }de'; 1.102 + 1.103 +// use braces in a normal quantifier construct 1.104 +status = inSection(5); 1.105 +try 1.106 +{ 1.107 + pattern = new RegExp('c{3}'); 1.108 + actualmatch = string.match(pattern); 1.109 +} 1.110 +catch (e) 1.111 +{ 1.112 + pattern = 'error'; 1.113 + actualmatch = ''; 1.114 +} 1.115 +expectedmatch = Array('ccc'); 1.116 +addThis(); 1.117 + 1.118 +// now disrupt the quantifer - the braces should now be interpreted literally 1.119 +status = inSection(6); 1.120 +try 1.121 +{ 1.122 + pattern = new RegExp('c{3 }'); 1.123 + actualmatch = string.match(pattern); 1.124 +} 1.125 +catch (e) 1.126 +{ 1.127 + pattern = 'error'; 1.128 + actualmatch = ''; 1.129 +} 1.130 +expectedmatch = Array('c{3 }'); 1.131 +addThis(); 1.132 + 1.133 +status = inSection(7); 1.134 +try 1.135 +{ 1.136 + pattern = new RegExp('c{3.}'); 1.137 + actualmatch = string.match(pattern); 1.138 +} 1.139 +catch (e) 1.140 +{ 1.141 + pattern = 'error'; 1.142 + actualmatch = ''; 1.143 +} 1.144 +expectedmatch = Array('c{3 }'); 1.145 +addThis(); 1.146 + 1.147 +status = inSection(8); 1.148 +try 1.149 +{ 1.150 + // need to escape the \ in \s since 1.151 + // this has been converted to a constructor call 1.152 + // instead of a literal regexp 1.153 + pattern = new RegExp('c{3\\s}'); 1.154 + actualmatch = string.match(pattern); 1.155 +} 1.156 +catch (e) 1.157 +{ 1.158 + pattern = 'error'; 1.159 + actualmatch = ''; 1.160 +} 1.161 +expectedmatch = Array('c{3 }'); 1.162 +addThis(); 1.163 + 1.164 +status = inSection(9); 1.165 +try 1.166 +{ 1.167 + pattern = new RegExp('c{3[ ]}'); 1.168 + actualmatch = string.match(pattern); 1.169 +} 1.170 +catch (e) 1.171 +{ 1.172 + pattern = 'error'; 1.173 + actualmatch = ''; 1.174 +} 1.175 +expectedmatch = Array('c{3 }'); 1.176 +addThis(); 1.177 + 1.178 +status = inSection(10); 1.179 +try 1.180 +{ 1.181 + pattern = new RegExp('c{ 3}'); 1.182 + actualmatch = string.match(pattern); 1.183 +} 1.184 +catch (e) 1.185 +{ 1.186 + pattern = 'error'; 1.187 + actualmatch = ''; 1.188 +} 1.189 +expectedmatch = Array('c{ 3}'); 1.190 +addThis(); 1.191 + 1.192 +// using braces in a normal quantifier construct again 1.193 +status = inSection(11); 1.194 +try 1.195 +{ 1.196 + pattern = new RegExp('c{3,}'); 1.197 + actualmatch = string.match(pattern); 1.198 +} 1.199 +catch (e) 1.200 +{ 1.201 + pattern = 'error'; 1.202 + actualmatch = ''; 1.203 +} 1.204 +expectedmatch = Array('ccccc'); 1.205 +addThis(); 1.206 + 1.207 +// now disrupt it - the braces should now be interpreted literally 1.208 +status = inSection(12); 1.209 +try 1.210 +{ 1.211 + pattern = new RegExp('c{3, }'); 1.212 + actualmatch = string.match(pattern); 1.213 +} 1.214 +catch (e) 1.215 +{ 1.216 + pattern = 'error'; 1.217 + actualmatch = ''; 1.218 +} 1.219 +expectedmatch = Array('c{3, }'); 1.220 +addThis(); 1.221 + 1.222 +status = inSection(13); 1.223 +try 1.224 +{ 1.225 + pattern = new RegExp('c{3 ,}'); 1.226 + actualmatch = string.match(pattern); 1.227 +} 1.228 +catch (e) 1.229 +{ 1.230 + pattern = 'error'; 1.231 + actualmatch = ''; 1.232 +} 1.233 +expectedmatch = Array('c{3 ,}'); 1.234 +addThis(); 1.235 + 1.236 +// using braces in a normal quantifier construct again 1.237 +status = inSection(14); 1.238 +try 1.239 +{ 1.240 + pattern = new RegExp('c{3,4}'); 1.241 + actualmatch = string.match(pattern); 1.242 +} 1.243 +catch (e) 1.244 +{ 1.245 + pattern = 'error'; 1.246 + actualmatch = ''; 1.247 +} 1.248 +expectedmatch = Array('cccc'); 1.249 +addThis(); 1.250 + 1.251 +// now disrupt it - the braces should now be interpreted literally 1.252 +status = inSection(15); 1.253 +try 1.254 +{ 1.255 + pattern = new RegExp('c{3 ,4}'); 1.256 + actualmatch = string.match(pattern); 1.257 +} 1.258 +catch (e) 1.259 +{ 1.260 + pattern = 'error'; 1.261 + actualmatch = ''; 1.262 +} 1.263 +expectedmatch = Array('c{3 ,4}'); 1.264 +addThis(); 1.265 + 1.266 +status = inSection(16); 1.267 +try 1.268 +{ 1.269 + pattern = new RegExp('c{3, 4}'); 1.270 + actualmatch = string.match(pattern); 1.271 +} 1.272 +catch (e) 1.273 +{ 1.274 + pattern = 'error'; 1.275 + actualmatch = ''; 1.276 +} 1.277 +expectedmatch = Array('c{3, 4}'); 1.278 +addThis(); 1.279 + 1.280 +status = inSection(17); 1.281 +try 1.282 +{ 1.283 + pattern = new RegExp('c{3,4 }'); 1.284 + actualmatch = string.match(pattern); 1.285 +} 1.286 +catch (e) 1.287 +{ 1.288 + pattern = 'error'; 1.289 + actualmatch = ''; 1.290 +} 1.291 +expectedmatch = Array('c{3,4 }'); 1.292 +addThis(); 1.293 + 1.294 + 1.295 + 1.296 + 1.297 +//------------------------------------------------------------------------------------------------- 1.298 +test(); 1.299 +//------------------------------------------------------------------------------------------------- 1.300 + 1.301 + 1.302 + 1.303 +function addThis() 1.304 +{ 1.305 + statusmessages[i] = status; 1.306 + patterns[i] = pattern; 1.307 + strings[i] = string; 1.308 + actualmatches[i] = actualmatch; 1.309 + expectedmatches[i] = expectedmatch; 1.310 + i++; 1.311 +} 1.312 + 1.313 + 1.314 +function test() 1.315 +{ 1.316 + enterFunc ('test'); 1.317 + printBugNumber(BUGNUMBER); 1.318 + printStatus (summary); 1.319 + testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 1.320 + exitFunc ('test'); 1.321 +}