JDK-8009230.js revision 178:1c29dc809de2
1/* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * JDK-8009230: Nashorn rejects extended RegExp syntax accepted by all major JS engines 26 * 27 * @test 28 * @run 29 */ 30 31 32// Invalid ControlEscape/IdentityEscape character treated as literal. 33print(/\z/.exec("z")); // Invalid escape, same as /z/ 34// Incomplete/Invalid ControlEscape treated as "\\c" 35print(/\c/.exec("\\c")); // same as /\\c/ 36print(/\c2/.exec("\\c2")); // same as /\\c2/ 37print(/\C/.exec("C")); // same as /C/ 38print(/\C2/.exec("C2")); // same as /C2/ 39// Incomplete HexEscapeSequence escape treated as "x". 40print(/\x/.exec("x")); // incomplete x-escape 41print(/\x1/.exec("x1")); // incomplete x-escape 42print(/\x1z/.exec("x1z")); // incomplete x-escape 43// Incomplete UnicodeEscapeSequence escape treated as "u". 44print(/\u/.exec("u")); // incomplete u-escape 45print(/\uz/.exec("uz")); // incomplete u-escape 46print(/\u1/.exec("u1")); // incomplete u-escape 47print(/\u1z/.exec("u1z")); // incomplete u-escape 48print(/\u12/.exec("u12")); // incomplete u-escape 49print(/\u12z/.exec("u12z")); // incomplete u-escape 50print(/\u123/.exec("u123")); // incomplete u-escape 51print(/\u123z/.exec("u123z")); // incomplete u-escape 52// Bad quantifier range: 53print(/x{z/.exec("x{z")); // same as /x\{z/ 54print(/x{1z/.exec("x{1z")); // same as /x\{1z/ 55print(/x{1,z/.exec("x{1,z")); // same as /x\{1,z/ 56print(/x{1,2z/.exec("x{1,2z")); // same as /x\{1,2z/ 57print(/x{10000,20000z/.exec("x{10000,20000z")); // same as /x\{10000,20000z/ 58// Notice: It needs arbitrary lookahead to determine the invalidity, 59// except Mozilla that limits the numbers. 60 61// Zero-initialized Octal escapes. 62/\012/; // same as /\x0a/ 63 64// Nonexisting back-references smaller than 8 treated as octal escapes: 65print(/\5/.exec("\u0005")); // same as /\x05/ 66print(/\7/.exec("\u0007")); // same as /\x07/ 67print(/\8/.exec("\u0008")); // does not match 68 69// Invalid PatternCharacter accepted unescaped 70print(/]/.exec("]")); 71print(/{/.exec("{")); 72print(/}/.exec("}")); 73 74// Bad escapes also inside CharacterClass. 75print(/[\z]/.exec("z")); 76print(/[\c]/.exec("c")); 77print(/[\c2]/.exec("c")); 78print(/[\x]/.exec("x")); 79print(/[\x1]/.exec("x1")); 80print(/[\x1z]/.exec("x1z")); 81print(/[\u]/.exec("u")); 82print(/[\uz]/.exec("u")); 83print(/[\u1]/.exec("u")); 84print(/[\u1z]/.exec("u")); 85print(/[\u12]/.exec("u")); 86print(/[\u12z]/.exec("u")); 87print(/[\u123]/.exec("u")); 88print(/[\u123z]/.exec("u")); 89print(/[\012]/.exec("0")); 90print(/[\5]/.exec("5")); 91// And in addition: 92print(/[\B]/.exec("B")); 93print(/()()[\2]/.exec("")); // Valid backreference should be invalid. 94