1/* 2* The contents of this file are subject to the Netscape Public 3* License Version 1.1 (the "License"); you may not use this file 4* except in compliance with the License. You may obtain a copy of 5* the License at http://www.mozilla.org/NPL/ 6* 7* Software distributed under the License is distributed on an "AS IS" 8* basis, WITHOUT WARRANTY OF ANY KIND, either expressed 9* or implied. See the License for the specific language governing 10* rights and limitations under the License. 11* 12* The Original Code is mozilla.org code. 13* 14* The Initial Developer of the Original Code is Netscape 15* Communications Corporation. Portions created by Netscape are 16* Copyright (C) 1998 Netscape Communications Corporation. 17* All Rights Reserved. 18* 19* Contributor(s): bedney@technicalpursuit.com, pschwartau@netscape.com 20* Date: 04 October 2001 21* 22* SUMMARY: Arose from Bugzilla bug 103087: 23* "The RegExp MarkupSPE in demo crashes Mozilla" 24* 25* See http://bugzilla.mozilla.org/show_bug.cgi?id=103087 26* The SpiderMonkey shell crashed on some of these regexps. 27* 28* The reported crash was on i=24 below ('MarkupSPE' regexp) 29* I crashed on that, and also on i=43 ('XML_SPE' regexp) 30*/ 31//----------------------------------------------------------------------------- 32var UBound = 0; 33var bug = 103087; 34var summary = "Testing that we don't crash on any of these regexps -"; 35var re = ''; 36var lm = ''; 37var lc = ''; 38var rc = ''; 39 40 41// the regexps are built in pieces - 42var NameStrt = "[A-Za-z_:]|[^\\x00-\\x7F]"; 43var NameChar = "[A-Za-z0-9_:.-]|[^\\x00-\\x7F]"; 44var Name = "(" + NameStrt + ")(" + NameChar + ")*"; 45var TextSE = "[^<]+"; 46var UntilHyphen = "[^-]*-"; 47var Until2Hyphens = UntilHyphen + "([^-]" + UntilHyphen + ")*-"; 48var CommentCE = Until2Hyphens + ">?"; 49var UntilRSBs = "[^]]*]([^]]+])*]+"; 50var CDATA_CE = UntilRSBs + "([^]>]" + UntilRSBs + ")*>"; 51var S = "[ \\n\\t\\r]+"; 52var QuoteSE = '"[^"]' + "*" + '"' + "|'[^']*'"; 53var DT_IdentSE = S + Name + "(" + S + "(" + Name + "|" + QuoteSE + "))*"; 54var MarkupDeclCE = "([^]\"'><]+|" + QuoteSE + ")*>"; 55var S1 = "[\\n\\r\\t ]"; 56var UntilQMs = "[^?]*\\?+"; 57var PI_Tail = "\\?>|" + S1 + UntilQMs + "([^>?]" + UntilQMs + ")*>"; 58var DT_ItemSE = "<(!(--" + Until2Hyphens + ">|[^-]" + MarkupDeclCE + ")|\\?" + Name + "(" + PI_Tail + "))|%" + Name + ";|" + S; 59var DocTypeCE = DT_IdentSE + "(" + S + ")?(\\[(" + DT_ItemSE + ")*](" + S + ")?)?>?"; 60var DeclCE = "--(" + CommentCE + ")?|\\[CDATA\\[(" + CDATA_CE + ")?|DOCTYPE(" + DocTypeCE + ")?"; 61var PI_CE = Name + "(" + PI_Tail + ")?"; 62var EndTagCE = Name + "(" + S + ")?>?"; 63var AttValSE = '"[^<"]' + "*" + '"' + "|'[^<']*'"; 64var ElemTagCE = Name + "(" + S + Name + "(" + S + ")?=(" + S + ")?(" + AttValSE + "))*(" + S + ")?/?>?"; 65var MarkupSPE = "<(!(" + DeclCE + ")?|\\?(" + PI_CE + ")?|/(" + EndTagCE + ")?|(" + ElemTagCE + ")?)"; 66var XML_SPE = TextSE + "|" + MarkupSPE; 67var CommentRE = "<!--" + Until2Hyphens + ">"; 68var CommentSPE = "<!--(" + CommentCE + ")?"; 69var PI_RE = "<\\?" + Name + "(" + PI_Tail + ")"; 70var Erroneous_PI_SE = "<\\?[^?]*(\\?[^>]+)*\\?>"; 71var PI_SPE = "<\\?(" + PI_CE + ")?"; 72var CDATA_RE = "<!\\[CDATA\\[" + CDATA_CE; 73var CDATA_SPE = "<!\\[CDATA\\[(" + CDATA_CE + ")?"; 74var ElemTagSE = "<(" + NameStrt + ")([^<>\"']+|" + AttValSE + ")*>"; 75var ElemTagRE = "<" + Name + "(" + S + Name + "(" + S + ")?=(" + S + ")?(" + AttValSE + "))*(" + S + ")?/?>"; 76var ElemTagSPE = "<" + ElemTagCE; 77var EndTagRE = "</" + Name + "(" + S + ")?>"; 78var EndTagSPE = "</(" + EndTagCE + ")?"; 79var DocTypeSPE = "<!DOCTYPE(" + DocTypeCE + ")?"; 80var PERef_APE = "%(" + Name + ";?)?"; 81var HexPart = "x([0-9a-fA-F]+;?)?"; 82var NumPart = "#([0-9]+;?|" + HexPart + ")?"; 83var CGRef_APE = "&(" + Name + ";?|" + NumPart + ")?"; 84var Text_PE = CGRef_APE + "|[^&]+"; 85var EntityValue_PE = CGRef_APE + "|" + PERef_APE + "|[^%&]+"; 86 87 88var 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); 89 90 91// here's a big string to test the regexps on - 92var str = ''; 93str += '<html xmlns="http://www.w3.org/1999/xhtml"' + '\n'; 94str += ' xmlns:xlink="http://www.w3.org/XML/XLink/0.9">' + '\n'; 95str += ' <head><title>Three Namespaces</title></head>' + '\n'; 96str += ' <body>' + '\n'; 97str += ' <h1 align="center">An Ellipse and a Rectangle</h1>' + '\n'; 98str += ' <svg xmlns="http://www.w3.org/Graphics/SVG/SVG-19991203.dtd" ' + '\n'; 99str += ' width="12cm" height="10cm">' + '\n'; 100str += ' <ellipse rx="110" ry="130" />' + '\n'; 101str += ' <rect x="4cm" y="1cm" width="3cm" height="6cm" />' + '\n'; 102str += ' </svg>' + '\n'; 103str += ' <p xlink:type="simple" xlink:href="ellipses.html">' + '\n'; 104str += ' More about ellipses' + '\n'; 105str += ' </p>' + '\n'; 106str += ' <p xlink:type="simple" xlink:href="rectangles.html">' + '\n'; 107str += ' More about rectangles' + '\n'; 108str += ' </p>' + '\n'; 109str += ' <hr/>' + '\n'; 110str += ' <p>Last Modified February 13, 2000</p> ' + '\n'; 111str += ' </body>' + '\n'; 112str += '</html>'; 113 114 115 116//----------------------------------------------------------------------------- 117test(); 118//----------------------------------------------------------------------------- 119 120 121 122function test() 123{ 124 enterFunc ('test'); 125 printBugNumber (bug); 126 printStatus (summary); 127 128 for (var i=0; i<rePatterns.length; i++) 129 { 130 status = inSection(i); 131 re = new RegExp(rePatterns[i]); 132 133 // Test that we don't crash on any of these - 134 re.exec(str); 135 getResults(); 136 137 // Just for the heck of it, test the current leftContext 138 re.exec(lc); 139 getResults(); 140 141 // Test the current rightContext 142 re.exec(rc); 143 getResults(); 144 } 145 146 exitFunc ('test'); 147} 148 149 150function getResults() 151{ 152 lm = RegExp.lastMatch; 153 lc = RegExp.leftContext; 154 rc = RegExp.rightContext; 155} 156