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 * bedney@technicalpursuit.com, pschwartau@netscape.com
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: 04 October 2001
42 * SUMMARY: Arose from Bugzilla bug 103087:
43 * "The RegExp MarkupSPE in demo crashes Mozilla"
45 * See http://bugzilla.mozilla.org/show_bug.cgi?id=103087
46 * The SpiderMonkey shell crashed on some of these regexps.
48 * The reported crash was on i=24 below ('MarkupSPE' regexp)
49 * I crashed on that, and also on i=43 ('XML_SPE' regexp)
51 //-----------------------------------------------------------------------------
52 var gTestfile = 'regress-103087.js';
54 var BUGNUMBER = 103087;
55 var summary = "Testing that we don't crash on any of these regexps -";
62 // the regexps are built in pieces -
63 var NameStrt = "[A-Za-z_:]|[^\\x00-\\x7F]";
64 var NameChar = "[A-Za-z0-9_:.-]|[^\\x00-\\x7F]";
65 var Name = "(" + NameStrt + ")(" + NameChar + ")*";
67 var UntilHyphen = "[^-]*-";
68 var Until2Hyphens = UntilHyphen + "([^-]" + UntilHyphen + ")*-";
69 var CommentCE = Until2Hyphens + ">?";
70 var UntilRSBs = "[^]]*]([^]]+])*]+";
71 var CDATA_CE = UntilRSBs + "([^]>]" + UntilRSBs + ")*>";
72 var S = "[ \\n\\t\\r]+";
73 var QuoteSE = '"[^"]' + "*" + '"' + "|'[^']*'";
74 var DT_IdentSE = S + Name + "(" + S + "(" + Name + "|" + QuoteSE + "))*";
75 var MarkupDeclCE = "([^]\"'><]+|" + QuoteSE + ")*>";
76 var S1 = "[\\n\\r\\t ]";
77 var UntilQMs = "[^?]*\\?+";
78 var PI_Tail = "\\?>|" + S1 + UntilQMs + "([^>?]" + UntilQMs + ")*>";
79 var DT_ItemSE = "<(!(--" + Until2Hyphens + ">|[^-]" + MarkupDeclCE + ")|\\?" + Name + "(" + PI_Tail + "))|%" + Name + ";|" + S;
80 var DocTypeCE = DT_IdentSE + "(" + S + ")?(\\[(" + DT_ItemSE + ")*](" + S + ")?)?>?";
81 var DeclCE = "--(" + CommentCE + ")?|\\[CDATA\\[(" + CDATA_CE + ")?|DOCTYPE(" + DocTypeCE + ")?";
82 var PI_CE = Name + "(" + PI_Tail + ")?";
83 var EndTagCE = Name + "(" + S + ")?>?";
84 var AttValSE = '"[^<"]' + "*" + '"' + "|'[^<']*'";
85 var ElemTagCE = Name + "(" + S + Name + "(" + S + ")?=(" + S + ")?(" + AttValSE + "))*(" + S + ")?/?>?";
86 var MarkupSPE = "<(!(" + DeclCE + ")?|\\?(" + PI_CE + ")?|/(" + EndTagCE + ")?|(" + ElemTagCE + ")?)";
87 var XML_SPE = TextSE + "|" + MarkupSPE;
88 var CommentRE = "<!--" + Until2Hyphens + ">";
89 var CommentSPE = "<!--(" + CommentCE + ")?";
90 var PI_RE = "<\\?" + Name + "(" + PI_Tail + ")";
91 var Erroneous_PI_SE = "<\\?[^?]*(\\?[^>]+)*\\?>";
92 var PI_SPE = "<\\?(" + PI_CE + ")?";
93 var CDATA_RE = "<!\\[CDATA\\[" + CDATA_CE;
94 var CDATA_SPE = "<!\\[CDATA\\[(" + CDATA_CE + ")?";
95 var ElemTagSE = "<(" + NameStrt + ")([^<>\"']+|" + AttValSE + ")*>";
96 var ElemTagRE = "<" + Name + "(" + S + Name + "(" + S + ")?=(" + S + ")?(" + AttValSE + "))*(" + S + ")?/?>";
97 var ElemTagSPE = "<" + ElemTagCE;
98 var EndTagRE = "</" + Name + "(" + S + ")?>";
99 var EndTagSPE = "</(" + EndTagCE + ")?";
100 var DocTypeSPE = "<!DOCTYPE(" + DocTypeCE + ")?";
101 var PERef_APE = "%(" + Name + ";?)?";
102 var HexPart = "x([0-9a-fA-F]+;?)?";
103 var NumPart = "#([0-9]+;?|" + HexPart + ")?";
104 var CGRef_APE = "&(" + Name + ";?|" + NumPart + ")?";
105 var Text_PE = CGRef_APE + "|[^&]+";
106 var EntityValue_PE = CGRef_APE + "|" + PERef_APE + "|[^%&]+";
109 var rePatterns = new Array(AttValSE, CDATA_CE, CDATA_RE, CDATA_SPE, CGRef_APE, CommentCE, CommentRE, CommentSPE, DT_IdentSE, DT_ItemSE, DeclCE, DocTypeCE, DocTypeSPE, ElemTagCE, ElemTagRE, ElemTagSE, ElemTagSPE, EndTagCE, EndTagRE, EndTagSPE, EntityValue_PE, Erroneous_PI_SE, HexPart, MarkupDeclCE, MarkupSPE, Name, NameChar, NameStrt, NumPart, PERef_APE, PI_CE, PI_RE, PI_SPE, PI_Tail, QuoteSE, S, S1, TextSE, Text_PE, Until2Hyphens, UntilHyphen, UntilQMs, UntilRSBs, XML_SPE);
112 // here's a big string to test the regexps on -
114 str += '<html xmlns="http://www.w3.org/1999/xhtml"' + '\n';
115 str += ' xmlns:xlink="http://www.w3.org/XML/XLink/0.9">' + '\n';
116 str += ' <head><title>Three Namespaces</title></head>' + '\n';
117 str += ' <body>' + '\n';
118 str += ' <h1 align="center">An Ellipse and a Rectangle</h1>' + '\n';
119 str += ' <svg xmlns="http://www.w3.org/Graphics/SVG/SVG-19991203.dtd" ' + '\n';
120 str += ' width="12cm" height="10cm">' + '\n';
121 str += ' <ellipse rx="110" ry="130" />' + '\n';
122 str += ' <rect x="4cm" y="1cm" width="3cm" height="6cm" />' + '\n';
123 str += ' </svg>' + '\n';
124 str += ' <p xlink:type="simple" xlink:href="ellipses.html">' + '\n';
125 str += ' More about ellipses' + '\n';
126 str += ' </p>' + '\n';
127 str += ' <p xlink:type="simple" xlink:href="rectangles.html">' + '\n';
128 str += ' More about rectangles' + '\n';
129 str += ' </p>' + '\n';
130 str += ' <hr/>' + '\n';
131 str += ' <p>Last Modified February 13, 2000</p> ' + '\n';
132 str += ' </body>' + '\n';
137 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
146 printBugNumber(BUGNUMBER);
147 printStatus (summary);
149 for (var i=0; i<rePatterns.length; i++)
151 status = inSection(i);
152 re = new RegExp(rePatterns[i]);
154 // Test that we don't crash on any of these -
158 // Just for the heck of it, test the current leftContext
162 // Test the current rightContext
167 reportCompare('No Crash', 'No Crash', '');
173 function getResults()
175 lm = RegExp.lastMatch;
176 lc = RegExp.leftContext;
177 rc = RegExp.rightContext;