1// Copyright 2013 the V8 project authors. All rights reserved. 2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions 6// are met: 7// 1. Redistributions of source code must retain the above copyright 8// notice, this list of conditions and the following disclaimer. 9// 2. Redistributions in binary form must reproduce the above copyright 10// notice, this list of conditions and the following disclaimer in the 11// documentation and/or other materials provided with the distribution. 12// 13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24description( 25'Tests for bug <a href="https://bugs.webkit.org/show_bug.cgi?id=21232">#21232</a>, and related range issues described in bug.' 26); 27 28// Basic test for ranges - one to three and five are in regexp, four is not, and '-' should not match 29var regexp01 = /[1-35]+/.exec("-12354"); 30shouldBe('regexp01.toString()', '"1235"'); 31// Tests inserting an escape character class into the above pattern - where the spaces fall within the 32// range it is no longer a range - hyphens should now match, two should not. 33var regexp01a = /[\s1-35]+/.exec("-123 54"); 34shouldBe('regexp01a.toString()', '"123 5"'); 35 36// These are invalid ranges, according to ECMA-262, but we allow them. 37var regexp01b = /[1\s-35]+/.exec("21-3 54"); 38shouldBe('regexp01b.toString()', '"1-3 5"'); 39var regexp01c = /[1-\s35]+/.exec("21-3 54"); 40shouldBe('regexp01c.toString()', '"1-3 5"'); 41 42var regexp01d = /[1-3\s5]+/.exec("-123 54"); 43shouldBe('regexp01d.toString()', '"123 5"'); 44var regexp01e = /[1-35\s5]+/.exec("-123 54"); 45shouldBe('regexp01e.toString()', '"123 5"'); 46// hyphens are normal charaters if a range is not fully specified. 47var regexp01f = /[-3]+/.exec("2-34"); 48shouldBe('regexp01f.toString()', '"-3"'); 49var regexp01g = /[2-]+/.exec("12-3"); 50shouldBe('regexp01g.toString()', '"2-"'); 51 52// Similar to the above tests, but where the hyphen is escaped this is never a range. 53var regexp02 = /[1\-35]+/.exec("21-354"); 54shouldBe('regexp02.toString()', '"1-35"'); 55// As above. 56var regexp02a = /[\s1\-35]+/.exec("21-3 54"); 57shouldBe('regexp02a.toString()', '"1-3 5"'); 58var regexp02b = /[1\s\-35]+/.exec("21-3 54"); 59shouldBe('regexp02b.toString()', '"1-3 5"'); 60var regexp02c = /[1\-\s35]+/.exec("21-3 54"); 61shouldBe('regexp02c.toString()', '"1-3 5"'); 62var regexp02d = /[1\-3\s5]+/.exec("21-3 54"); 63shouldBe('regexp02d.toString()', '"1-3 5"'); 64var regexp02e = /[1\-35\s5]+/.exec("21-3 54"); 65shouldBe('regexp02e.toString()', '"1-3 5"'); 66 67// Test that an escaped hyphen can be used as a bound on a range. 68var regexp03a = /[\--0]+/.exec(",-.01"); 69shouldBe('regexp03a.toString()', '"-.0"'); 70var regexp03b = /[+-\-]+/.exec("*+,-."); 71shouldBe('regexp03b.toString()', '"+,-"'); 72 73// The actual bug reported. 74var bug21232 = (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test('@'); 75shouldBe('bug21232', 'false'); 76