aoqi@0: /* aoqi@0: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * JDK-8009230: Nashorn rejects extended RegExp syntax accepted by all major JS engines aoqi@0: * aoqi@0: * @test aoqi@0: * @run aoqi@0: */ aoqi@0: aoqi@0: aoqi@0: // Invalid ControlEscape/IdentityEscape character treated as literal. aoqi@0: print(/\z/.exec("z")); // Invalid escape, same as /z/ aoqi@0: // Incomplete/Invalid ControlEscape treated as "\\c" aoqi@0: print(/\c/.exec("\\c")); // same as /\\c/ aoqi@0: print(/\c2/.exec("\\c2")); // same as /\\c2/ aoqi@0: print(/\C/.exec("C")); // same as /C/ aoqi@0: print(/\C2/.exec("C2")); // same as /C2/ aoqi@0: // Incomplete HexEscapeSequence escape treated as "x". aoqi@0: print(/\x/.exec("x")); // incomplete x-escape aoqi@0: print(/\x1/.exec("x1")); // incomplete x-escape aoqi@0: print(/\x1z/.exec("x1z")); // incomplete x-escape aoqi@0: // Incomplete UnicodeEscapeSequence escape treated as "u". aoqi@0: print(/\u/.exec("u")); // incomplete u-escape aoqi@0: print(/\uz/.exec("uz")); // incomplete u-escape aoqi@0: print(/\u1/.exec("u1")); // incomplete u-escape aoqi@0: print(/\u1z/.exec("u1z")); // incomplete u-escape aoqi@0: print(/\u12/.exec("u12")); // incomplete u-escape aoqi@0: print(/\u12z/.exec("u12z")); // incomplete u-escape aoqi@0: print(/\u123/.exec("u123")); // incomplete u-escape aoqi@0: print(/\u123z/.exec("u123z")); // incomplete u-escape aoqi@0: // Bad quantifier range: aoqi@0: print(/x{z/.exec("x{z")); // same as /x\{z/ aoqi@0: print(/x{1z/.exec("x{1z")); // same as /x\{1z/ aoqi@0: print(/x{1,z/.exec("x{1,z")); // same as /x\{1,z/ aoqi@0: print(/x{1,2z/.exec("x{1,2z")); // same as /x\{1,2z/ aoqi@0: print(/x{10000,20000z/.exec("x{10000,20000z")); // same as /x\{10000,20000z/ aoqi@0: // Notice: It needs arbitrary lookahead to determine the invalidity, aoqi@0: // except Mozilla that limits the numbers. aoqi@0: aoqi@0: // Zero-initialized Octal escapes. aoqi@0: /\012/; // same as /\x0a/ aoqi@0: aoqi@0: // Nonexisting back-references smaller than 8 treated as octal escapes: aoqi@0: print(/\5/.exec("\u0005")); // same as /\x05/ aoqi@0: print(/\7/.exec("\u0007")); // same as /\x07/ aoqi@0: print(/\8/.exec("\u0008")); // does not match aoqi@0: aoqi@0: // Invalid PatternCharacter accepted unescaped aoqi@0: print(/]/.exec("]")); aoqi@0: print(/{/.exec("{")); aoqi@0: print(/}/.exec("}")); aoqi@0: aoqi@0: // Bad escapes also inside CharacterClass. aoqi@0: print(/[\z]/.exec("z")); aoqi@0: print(/[\c]/.exec("c")); aoqi@0: print(/[\c2]/.exec("c")); aoqi@0: print(/[\x]/.exec("x")); aoqi@0: print(/[\x1]/.exec("x1")); aoqi@0: print(/[\x1z]/.exec("x1z")); aoqi@0: print(/[\u]/.exec("u")); aoqi@0: print(/[\uz]/.exec("u")); aoqi@0: print(/[\u1]/.exec("u")); aoqi@0: print(/[\u1z]/.exec("u")); aoqi@0: print(/[\u12]/.exec("u")); aoqi@0: print(/[\u12z]/.exec("u")); aoqi@0: print(/[\u123]/.exec("u")); aoqi@0: print(/[\u123z]/.exec("u")); aoqi@0: print(/[\012]/.exec("0")); aoqi@0: print(/[\5]/.exec("5")); aoqi@0: // And in addition: aoqi@0: print(/[\B]/.exec("B")); aoqi@0: print(/()()[\2]/.exec("")); // Valid backreference should be invalid.