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

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

Issue 2791183002: [regexp] Throw on invalid capture group names in replacer string (Closed)
Patch Set: Typo Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-strings.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/regexp-named-captures.js
diff --git a/test/mjsunit/harmony/regexp-named-captures.js b/test/mjsunit/harmony/regexp-named-captures.js
index 42b3b31c7fc5505bdf5b9e2be8bb0882aef39696..f40371b4865429ee664616731d10da2665e6f862 100644
--- a/test/mjsunit/harmony/regexp-named-captures.js
+++ b/test/mjsunit/harmony/regexp-named-captures.js
@@ -263,56 +263,61 @@ function toSlowMode(re) {
// @@replace with a string replacement argument (no named captures).
{
- let re = /(.)(.)/u;
+ let re = /(.)(.)|(x)/u;
assertEquals("$<snd>$<fst>cd", "abcd".replace(re, "$<snd>$<fst>"));
assertEquals("bacd", "abcd".replace(re, "$2$1"));
+ assertEquals("cd", "abcd".replace(re, "$3"));
assertEquals("$<sndcd", "abcd".replace(re, "$<snd"));
assertEquals("$<42a>cd", "abcd".replace(re, "$<42$1>"));
- assertEquals("$<thd>cd", "abcd".replace(re, "$<thd>"));
+ assertEquals("$<fth>cd", "abcd".replace(re, "$<fth>"));
assertEquals("$<a>cd", "abcd".replace(re, "$<$1>"));
}
// @@replace with a string replacement argument (global, named captures).
{
- let re = /(?<fst>.)(?<snd>.)/gu;
+ let re = /(?<fst>.)(?<snd>.)|(?<thd>x)/gu;
assertEquals("badc", "abcd".replace(re, "$<snd>$<fst>"));
assertEquals("badc", "abcd".replace(re, "$2$1"));
- assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
- assertEquals("", "abcd".replace(re, "$<42$1>"));
assertEquals("", "abcd".replace(re, "$<thd>"));
- assertEquals("", "abcd".replace(re, "$<$1>"));
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<42$1>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<fth>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<$1>"), SyntaxError);
}
// @@replace with a string replacement argument (non-global, named captures).
{
- let re = /(?<fst>.)(?<snd>.)/u;
+ let re = /(?<fst>.)(?<snd>.)|(?<thd>x)/u;
assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>"));
assertEquals("bacd", "abcd".replace(re, "$2$1"));
- assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
- assertEquals("cd", "abcd".replace(re, "$<42$1>"));
assertEquals("cd", "abcd".replace(re, "$<thd>"));
- assertEquals("cd", "abcd".replace(re, "$<$1>"));
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<42$1>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<fth>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<$1>"), SyntaxError);
}
// @@replace with a string replacement argument (slow, global, named captures).
{
- let re = toSlowMode(/(?<fst>.)(?<snd>.)/gu);
+ let re = toSlowMode(/(?<fst>.)(?<snd>.)|(?<thd>x)/gu);
assertEquals("badc", "abcd".replace(re, "$<snd>$<fst>"));
assertEquals("badc", "abcd".replace(re, "$2$1"));
- assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
- assertEquals("", "abcd".replace(re, "$<42$1>"));
assertEquals("", "abcd".replace(re, "$<thd>"));
- assertEquals("", "abcd".replace(re, "$<$1>"));
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<42$1>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<fth>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<$1>"), SyntaxError);
}
// @@replace with a string replacement argument (slow, non-global,
// named captures).
{
- let re = toSlowMode(/(?<fst>.)(?<snd>.)/u);
+ let re = toSlowMode(/(?<fst>.)(?<snd>.)|(?<thd>x)/u);
assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>"));
assertEquals("bacd", "abcd".replace(re, "$2$1"));
- assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
- assertEquals("cd", "abcd".replace(re, "$<42$1>"));
assertEquals("cd", "abcd".replace(re, "$<thd>"));
- assertEquals("cd", "abcd".replace(re, "$<$1>"));
+ assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<42$1>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<fth>"), SyntaxError);
+ assertThrows(() => "abcd".replace(re, "$<$1>"), SyntaxError);
}
« no previous file with comments | « src/runtime/runtime-strings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698