Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/mjsunit/harmony/regexp-named-captures.js

Issue 2795093003: [regexp] Disallow '\' in capture names (Closed)
Patch Set: Also fix ID_Continue Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-regexp-named-captures --harmony-regexp-lookbehind 5 // Flags: --harmony-regexp-named-captures --harmony-regexp-lookbehind
6 6
7 // Malformed named captures. 7 // Malformed named captures.
8 assertThrows("/(?<>a)/u", SyntaxError); // Empty name. 8 assertThrows("/(?<>a)/u", SyntaxError); // Empty name.
9 assertThrows("/(?<aa)/u", SyntaxError); // Unterminated name. 9 assertThrows("/(?<aa)/u", SyntaxError); // Unterminated name.
10 assertThrows("/(?<42a>a)/u", SyntaxError); // Name starting with digits. 10 assertThrows("/(?<42a>a)/u", SyntaxError); // Name starting with digits.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 // Properties created on result.groups. 171 // Properties created on result.groups.
172 assertEquals(["fst", "snd"], 172 assertEquals(["fst", "snd"],
173 Object.getOwnPropertyNames( 173 Object.getOwnPropertyNames(
174 /(?<fst>.)|(?<snd>.)/u.exec("abcd").groups)); 174 /(?<fst>.)|(?<snd>.)/u.exec("abcd").groups));
175 175
176 // The '__proto__' property on the groups object. 176 // The '__proto__' property on the groups object.
177 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); 177 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__);
178 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); 178 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__);
179 179
180 // Backslash as ID_Start and ID_Continue (v8:5868).
181 assertThrows("/(?<\\>.)/", SyntaxError); // '\' misclassified as ID_Start.
182 assertThrows("/(?<a\\>.)/", SyntaxError); // '\' misclassified as ID_Continue.
183
180 // Backreference before the group (exercises the capture mini-parser). 184 // Backreference before the group (exercises the capture mini-parser).
181 assertThrows("/\\1(?:.)/u", SyntaxError); 185 assertThrows("/\\1(?:.)/u", SyntaxError);
182 assertThrows("/\\1(?<=a)./u", SyntaxError); 186 assertThrows("/\\1(?<=a)./u", SyntaxError);
183 assertThrows("/\\1(?<!a)./u", SyntaxError); 187 assertThrows("/\\1(?<!a)./u", SyntaxError);
184 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); 188 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd"));
185 189
186 // @@replace with a callable replacement argument (no named captures). 190 // @@replace with a callable replacement argument (no named captures).
187 { 191 {
188 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { 192 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => {
189 assertEquals("ab", match); 193 assertEquals("ab", match);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // named captures). 366 // named captures).
363 { 367 {
364 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); 368 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u);
365 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); 369 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>"));
366 assertEquals("bacd", "abcd".replace(re, "$2$1")); 370 assertEquals("bacd", "abcd".replace(re, "$2$1"));
367 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); 371 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
368 assertEquals("cd", "abcd".replace(re, "$<42$1>")); 372 assertEquals("cd", "abcd".replace(re, "$<42$1>"));
369 assertEquals("cd", "abcd".replace(re, "$<thd>")); 373 assertEquals("cd", "abcd".replace(re, "$<thd>"));
370 assertEquals("cd", "abcd".replace(re, "$<$1>")); 374 assertEquals("cd", "abcd".replace(re, "$<$1>"));
371 } 375 }
OLDNEW
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698