|
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. |
|
33 print(/\z/.exec("z")); // Invalid escape, same as /z/ |
|
34 // Incomplete/Invalid ControlEscape treated as "\\c" |
|
35 print(/\c/.exec("\\c")); // same as /\\c/ |
|
36 print(/\c2/.exec("\\c2")); // same as /\\c2/ |
|
37 print(/\C/.exec("C")); // same as /C/ |
|
38 print(/\C2/.exec("C2")); // same as /C2/ |
|
39 // Incomplete HexEscapeSequence escape treated as "x". |
|
40 print(/\x/.exec("x")); // incomplete x-escape |
|
41 print(/\x1/.exec("x1")); // incomplete x-escape |
|
42 print(/\x1z/.exec("x1z")); // incomplete x-escape |
|
43 // Incomplete UnicodeEscapeSequence escape treated as "u". |
|
44 print(/\u/.exec("u")); // incomplete u-escape |
|
45 print(/\uz/.exec("uz")); // incomplete u-escape |
|
46 print(/\u1/.exec("u1")); // incomplete u-escape |
|
47 print(/\u1z/.exec("u1z")); // incomplete u-escape |
|
48 print(/\u12/.exec("u12")); // incomplete u-escape |
|
49 print(/\u12z/.exec("u12z")); // incomplete u-escape |
|
50 print(/\u123/.exec("u123")); // incomplete u-escape |
|
51 print(/\u123z/.exec("u123z")); // incomplete u-escape |
|
52 // Bad quantifier range: |
|
53 print(/x{z/.exec("x{z")); // same as /x\{z/ |
|
54 print(/x{1z/.exec("x{1z")); // same as /x\{1z/ |
|
55 print(/x{1,z/.exec("x{1,z")); // same as /x\{1,z/ |
|
56 print(/x{1,2z/.exec("x{1,2z")); // same as /x\{1,2z/ |
|
57 print(/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: |
|
65 print(/\5/.exec("\u0005")); // same as /\x05/ |
|
66 print(/\7/.exec("\u0007")); // same as /\x07/ |
|
67 print(/\8/.exec("\u0008")); // does not match |
|
68 |
|
69 // Invalid PatternCharacter accepted unescaped |
|
70 print(/]/.exec("]")); |
|
71 print(/{/.exec("{")); |
|
72 print(/}/.exec("}")); |
|
73 |
|
74 // Bad escapes also inside CharacterClass. |
|
75 print(/[\z]/.exec("z")); |
|
76 print(/[\c]/.exec("c")); |
|
77 print(/[\c2]/.exec("c")); |
|
78 print(/[\x]/.exec("x")); |
|
79 print(/[\x1]/.exec("x1")); |
|
80 print(/[\x1z]/.exec("x1z")); |
|
81 print(/[\u]/.exec("u")); |
|
82 print(/[\uz]/.exec("u")); |
|
83 print(/[\u1]/.exec("u")); |
|
84 print(/[\u1z]/.exec("u")); |
|
85 print(/[\u12]/.exec("u")); |
|
86 print(/[\u12z]/.exec("u")); |
|
87 print(/[\u123]/.exec("u")); |
|
88 print(/[\u123z]/.exec("u")); |
|
89 print(/[\012]/.exec("0")); |
|
90 print(/[\5]/.exec("5")); |
|
91 // And in addition: |
|
92 print(/[\B]/.exec("B")); |
|
93 print(/()()[\2]/.exec("")); // Valid backreference should be invalid. |