1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-122076.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 Feb 2002 1.12 + * SUMMARY: Don't crash on invalid regexp literals / \\/ / 1.13 + * 1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=122076 1.15 + * The function checkURL() below sometimes caused a compile-time error: 1.16 + * 1.17 + * SyntaxError: unterminated parenthetical (: 1.18 + * 1.19 + * However, sometimes it would cause a crash instead. The presence of 1.20 + * other functions below is merely fodder to help provoke the crash. 1.21 + * The constant |STRESS| is number of times we'll try to crash on this. 1.22 + * 1.23 + */ 1.24 +//----------------------------------------------------------------------------- 1.25 +var BUGNUMBER = 122076; 1.26 +var summary = "Don't crash on invalid regexp literals / \\/ /"; 1.27 +var STRESS = 10; 1.28 +var sEval = ''; 1.29 + 1.30 +printBugNumber(BUGNUMBER); 1.31 +printStatus(summary); 1.32 + 1.33 + 1.34 +sEval += 'function checkDate()' 1.35 +sEval += '{' 1.36 +sEval += 'return (this.value.search(/^[012]?\d\/[0123]?\d\/[0]\d$/) != -1);' 1.37 +sEval += '}' 1.38 + 1.39 +sEval += 'function checkDNSName()' 1.40 +sEval += '{' 1.41 +sEval += ' return (this.value.search(/^([\w\-]+\.)+([\w\-]{2,3})$/) != -1);' 1.42 +sEval += '}' 1.43 + 1.44 +sEval += 'function checkEmail()' 1.45 +sEval += '{' 1.46 +sEval += ' return (this.value.search(/^([\w\-]+\.)*[\w\-]+@([\w\-]+\.)+([\w\-]{2,3})$/) != -1);' 1.47 +sEval += '}' 1.48 + 1.49 +sEval += 'function checkHostOrIP()' 1.50 +sEval += '{' 1.51 +sEval += ' if (this.value.search(/^([\w\-]+\.)+([\w\-]{2,3})$/) == -1)' 1.52 +sEval += ' return (this.value.search(/^[1-2]?\d{1,2}\.[1-2]?\d{1,2}\.[1-2]?\d{1,2}\.[1-2]?\d{1,2}$/) != -1);' 1.53 +sEval += ' else' 1.54 +sEval += ' return true;' 1.55 +sEval += '}' 1.56 + 1.57 +sEval += 'function checkIPAddress()' 1.58 +sEval += '{' 1.59 +sEval += ' return (this.value.search(/^[1-2]?\d{1,2}\.[1-2]?\d{1,2}\.[1-2]?\d{1,2}\.[1-2]?\d{1,2}$/) != -1);' 1.60 +sEval += '}' 1.61 + 1.62 +sEval += 'function checkURL()' 1.63 +sEval += '{' 1.64 +sEval += ' return (this.value.search(/^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,4}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\/\*\$+@&#;`~=%!]*)(\.\w{2,})?)*\/?)$/) != -1);' 1.65 +sEval += '}' 1.66 + 1.67 + 1.68 +for (var i=0; i<STRESS; i++) 1.69 +{ 1.70 + try 1.71 + { 1.72 + eval(sEval); 1.73 + } 1.74 + catch(e) 1.75 + { 1.76 + } 1.77 +} 1.78 + 1.79 +reportCompare('No Crash', 'No Crash', '');