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 24 description( 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 29 var regexp01 = /[1-35]+/.exec("-12354"); 30 shouldBe('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. 33 var regexp01a = /[\s1-35]+/.exec("-123 54"); 34 shouldBe('regexp01a.toString()', '"123 5"'); 35 36 // These are invalid ranges, according to ECMA-262, but we allow them. 37 var regexp01b = /[1\s-35]+/.exec("21-3 54"); 38 shouldBe('regexp01b.toString()', '"1-3 5"'); 39 var regexp01c = /[1-\s35]+/.exec("21-3 54"); 40 shouldBe('regexp01c.toString()', '"1-3 5"'); 41 42 var regexp01d = /[1-3\s5]+/.exec("-123 54"); 43 shouldBe('regexp01d.toString()', '"123 5"'); 44 var regexp01e = /[1-35\s5]+/.exec("-123 54"); 45 shouldBe('regexp01e.toString()', '"123 5"'); 46 // hyphens are normal charaters if a range is not fully specified. 47 var regexp01f = /[-3]+/.exec("2-34"); 48 shouldBe('regexp01f.toString()', '"-3"'); 49 var regexp01g = /[2-]+/.exec("12-3"); 50 shouldBe('regexp01g.toString()', '"2-"'); 51 52 // Similar to the above tests, but where the hyphen is escaped this is never a range. 53 var regexp02 = /[1\-35]+/.exec("21-354"); 54 shouldBe('regexp02.toString()', '"1-35"'); 55 // As above. 56 var regexp02a = /[\s1\-35]+/.exec("21-3 54"); 57 shouldBe('regexp02a.toString()', '"1-3 5"'); 58 var regexp02b = /[1\s\-35]+/.exec("21-3 54"); 59 shouldBe('regexp02b.toString()', '"1-3 5"'); 60 var regexp02c = /[1\-\s35]+/.exec("21-3 54"); 61 shouldBe('regexp02c.toString()', '"1-3 5"'); 62 var regexp02d = /[1\-3\s5]+/.exec("21-3 54"); 63 shouldBe('regexp02d.toString()', '"1-3 5"'); 64 var regexp02e = /[1\-35\s5]+/.exec("21-3 54"); 65 shouldBe('regexp02e.toString()', '"1-3 5"'); 66 67 // Test that an escaped hyphen can be used as a bound on a range. 68 var regexp03a = /[\--0]+/.exec(",-.01"); 69 shouldBe('regexp03a.toString()', '"-.0"'); 70 var regexp03b = /[+-\-]+/.exec("*+,-."); 71 shouldBe('regexp03b.toString()', '"+,-"'); 72 73 // The actual bug reported. 74 var bug21232 = (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test('@'); 75 shouldBe('bug21232', 'false'); 76