18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* The contents of this file are subject to the Netscape Public 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* License Version 1.1 (the "License"); you may not use this file 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* except in compliance with the License. You may obtain a copy of 58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* the License at http://www.mozilla.org/NPL/ 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Software distributed under the License is distributed on an "AS 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* implied. See the License for the specific language governing 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* rights and limitations under the License. 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* The Original Code is mozilla.org code. 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* The Initial Developer of the Original Code is Netscape 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Communications Corporation. Portions created by Netscape are 168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Copyright (C) 1998 Netscape Communications Corporation. All 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Rights Reserved. 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Contributor(s): pschwartau@netscape.com 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Date: 26 November 2000 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* SUMMARY: This test arose from Bugzilla bug 57631: 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* "RegExp with invalid pattern or invalid flag causes segfault" 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Either error should throw an exception of type SyntaxError, 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* and we check to see that it does... 288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project*/ 298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project//------------------------------------------------------------------------------------------------- 308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar bug = '57631'; 318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar summary = 'Testing new RegExp(pattern,flag) with illegal pattern or flag'; 328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar statprefix = 'Testing for error creating illegal RegExp object on pattern '; 338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar statsuffix = 'and flag '; 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar cnSUCCESS = 'SyntaxError'; 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar cnFAILURE = 'not a SyntaxError'; 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar singlequote = "'"; 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar i = -1; var j = -1; var s = ''; var f = ''; 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar obj = {}; 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar status = ''; var actual = ''; var expect = ''; var msg = ''; 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar legalpatterns = new Array(); var illegalpatterns = new Array(); 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar legalflags = new Array(); var illegalflags = new Array(); 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// valid regular expressions to try - 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalpatterns[0] = ''; 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalpatterns[1] = 'abc'; 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalpatterns[2] = '(.*)(3-1)\s\w'; 488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalpatterns[3] = '(.*)(...)\\s\\w'; 498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalpatterns[4] = '[^A-Za-z0-9_]'; 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalpatterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)'; 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// invalid regular expressions to try - 538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectillegalpatterns[0] = '()'; 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectillegalpatterns[1] = '(a'; 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectillegalpatterns[2] = '( ]'; 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectillegalpatterns[3] = '\d{s}'; 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// valid flags to try - 598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalflags[0] = 'i'; 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalflags[1] = 'g'; 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalflags[2] = 'm'; 628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectlegalflags[3] = undefined; 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// invalid flags to try - 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectillegalflags[0] = 'a'; 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectillegalflags[1] = 123; 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectillegalflags[2] = new RegExp(); 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project//------------------------------------------------------------------------------------------------- 728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projecttest(); 738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project//------------------------------------------------------------------------------------------------- 748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction test() 778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project enterFunc ('test'); 798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project printBugNumber (bug); 808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project printStatus (summary); 818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project testIllegalRegExps(legalpatterns, illegalflags); 838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project testIllegalRegExps(illegalpatterns, legalflags); 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project testIllegalRegExps(illegalpatterns, illegalflags); 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project exitFunc ('test'); 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// This function will only be called where all the patterns are illegal, or all the flags 918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction testIllegalRegExps(patterns, flags) 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project for (i in patterns) 948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project { 958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project s = patterns[i]; 968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project for (j in flags) 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project { 998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project f = flags[j]; 1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project status = getStatus(s, f); 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project try 1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project { 1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // This should cause an exception if either s or f is illegal - 1058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project eval('obj = new RegExp(s, f);'); 1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project catch(e) 1088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project { 1098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We expect to get a SyntaxError - test for this: 1108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project actual = (e instanceof SyntaxError)? cnSUCCESS : cnFAILURE; 1118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project expect = cnSUCCESS; 1128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project reportCompare(expect, actual, status); 1138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction getStatus(regexp, flag) 1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return (statprefix + quote(regexp) + statsuffix + quote(flag)); 1228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction quote(text) 1268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return (singlequote + text + singlequote); 1288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}