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