1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * pschwartau@netscape.com, zack-weg@gmx.de
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * Date: 26 November 2000
43 * SUMMARY: This test arose from Bugzilla bug 57631:
44 * "RegExp with invalid pattern or invalid flag causes segfault"
46 * Either error should throw an exception of type SyntaxError,
47 * and we check to see that it does...
49 //-----------------------------------------------------------------------------
50 var BUGNUMBER = '57631';
51 var summary = 'Testing new RegExp(pattern,flag) with illegal pattern or flag';
52 var statprefix = 'Testing for error creating illegal RegExp object on pattern ';
53 var statsuffix = 'and flag ';
54 var cnSUCCESS = 'SyntaxError';
55 var cnFAILURE = 'not a SyntaxError';
56 var singlequote = "'";
57 var i = -1; var j = -1; var s = ''; var f = '';
59 var status = ''; var actual = ''; var expect = ''; var msg = '';
60 var legalpatterns = new Array(); var illegalpatterns = new Array();
61 var legalflags = new Array(); var illegalflags = new Array();
64 // valid regular expressions to try -
65 legalpatterns[0] = '';
66 legalpatterns[1] = 'abc';
67 legalpatterns[2] = '(.*)(3-1)\s\w';
68 legalpatterns[3] = '(.*)(...)\\s\\w';
69 legalpatterns[4] = '[^A-Za-z0-9_]';
70 legalpatterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
72 // invalid regular expressions to try -
73 illegalpatterns[0] = '(?)';
74 illegalpatterns[1] = '(a';
75 illegalpatterns[2] = '( ]';
76 //illegalpatterns[3] = '\d{1,s}';
78 // valid flags to try -
82 legalflags[3] = undefined;
84 // invalid flags to try -
85 illegalflags[0] = 'a';
86 illegalflags[1] = 123;
87 illegalflags[2] = new RegExp();
91 //-------------------------------------------------------------------------------------------------
93 //-------------------------------------------------------------------------------------------------
99 printBugNumber(BUGNUMBER);
100 printStatus (summary);
102 testIllegalRegExps(legalpatterns, illegalflags);
103 testIllegalRegExps(illegalpatterns, legalflags);
104 testIllegalRegExps(illegalpatterns, illegalflags);
110 // This function will only be called where all the patterns are illegal, or all the flags
111 function testIllegalRegExps(patterns, flags)
120 status = getStatus(s, f);
126 // This should cause an exception if either s or f is illegal -
127 eval('obj = new RegExp(s, f);');
131 // We expect to get a SyntaxError - test for this:
132 if (e instanceof SyntaxError)
136 reportCompare(expect, actual, status);
142 function getStatus(regexp, flag)
144 return (statprefix + quote(regexp) + statsuffix + quote(flag));
150 return (singlequote + text + singlequote);