1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-105972.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,123 @@ 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 + * Date: 22 October 2001 1.11 + * 1.12 + * SUMMARY: Regression test for Bugzilla bug 105972: 1.13 + * "/^.*?$/ will not match anything" 1.14 + * 1.15 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=105972 1.16 + */ 1.17 +//----------------------------------------------------------------------------- 1.18 +var i = 0; 1.19 +var BUGNUMBER = 105972; 1.20 +var summary = 'Regression test for Bugzilla bug 105972'; 1.21 +var cnEmptyString = ''; 1.22 +var status = ''; 1.23 +var statusmessages = new Array(); 1.24 +var pattern = ''; 1.25 +var patterns = new Array(); 1.26 +var string = ''; 1.27 +var strings = new Array(); 1.28 +var actualmatch = ''; 1.29 +var actualmatches = new Array(); 1.30 +var expectedmatch = ''; 1.31 +var expectedmatches = new Array(); 1.32 + 1.33 + 1.34 +/* 1.35 + * The bug: this match was coming up null in Rhino and SpiderMonkey. 1.36 + * It should match the whole string. The reason: 1.37 + * 1.38 + * The * operator is greedy, but *? is non-greedy: it will stop 1.39 + * at the simplest match it can find. But the pattern here asks us 1.40 + * to match till the end of the string. So the simplest match must 1.41 + * go all the way out to the end, and *? has no choice but to do it. 1.42 + */ 1.43 +status = inSection(1); 1.44 +pattern = /^.*?$/; 1.45 +string = 'Hello World'; 1.46 +actualmatch = string.match(pattern); 1.47 +expectedmatch = Array(string); 1.48 +addThis(); 1.49 + 1.50 + 1.51 +/* 1.52 + * Leave off the '$' condition - here we expect the empty string. 1.53 + * Unlike the above pattern, we don't have to match till the end of 1.54 + * the string, so the non-greedy operator *? doesn't try to... 1.55 + */ 1.56 +status = inSection(2); 1.57 +pattern = /^.*?/; 1.58 +string = 'Hello World'; 1.59 +actualmatch = string.match(pattern); 1.60 +expectedmatch = Array(cnEmptyString); 1.61 +addThis(); 1.62 + 1.63 + 1.64 +/* 1.65 + * Try '$' combined with an 'or' operator. 1.66 + * 1.67 + * The operator *? will consume the string from left to right, 1.68 + * attempting to satisfy the condition (:|$). When it hits ':', 1.69 + * the match will stop because the operator *? is non-greedy. 1.70 + * 1.71 + * The submatch $1 = (:|$) will contain the ':' 1.72 + */ 1.73 +status = inSection(3); 1.74 +pattern = /^.*?(:|$)/; 1.75 +string = 'Hello: World'; 1.76 +actualmatch = string.match(pattern); 1.77 +expectedmatch = Array('Hello:', ':'); 1.78 +addThis(); 1.79 + 1.80 + 1.81 +/* 1.82 + * Again, '$' combined with an 'or' operator. 1.83 + * 1.84 + * The operator * will consume the string from left to right, 1.85 + * attempting to satisfy the condition (:|$). When it hits ':', 1.86 + * the match will not stop since * is greedy. The match will 1.87 + * continue until it hits $, the end-of-string boundary. 1.88 + * 1.89 + * The submatch $1 = (:|$) will contain the empty string 1.90 + * conceived to exist at the end-of-string boundary. 1.91 + */ 1.92 +status = inSection(4); 1.93 +pattern = /^.*(:|$)/; 1.94 +string = 'Hello: World'; 1.95 +actualmatch = string.match(pattern); 1.96 +expectedmatch = Array(string, cnEmptyString); 1.97 +addThis(); 1.98 + 1.99 + 1.100 + 1.101 + 1.102 +//----------------------------------------------------------------------------- 1.103 +test(); 1.104 +//----------------------------------------------------------------------------- 1.105 + 1.106 + 1.107 + 1.108 +function addThis() 1.109 +{ 1.110 + statusmessages[i] = status; 1.111 + patterns[i] = pattern; 1.112 + strings[i] = string; 1.113 + actualmatches[i] = actualmatch; 1.114 + expectedmatches[i] = expectedmatch; 1.115 + i++; 1.116 +} 1.117 + 1.118 + 1.119 +function test() 1.120 +{ 1.121 + enterFunc ('test'); 1.122 + printBugNumber(BUGNUMBER); 1.123 + printStatus (summary); 1.124 + testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 1.125 + exitFunc ('test'); 1.126 +}