Bug 854124 - Update RegExpStatics on empty match in str_replace_regexp_remove(). r=dvander

This commit is contained in:
Sean Stangl 2013-04-01 15:35:27 -07:00
parent d46c720a8d
commit 001adc7fbf
2 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,8 @@
// Don't assert.
"p".match(/(p)/);
assertEq(RegExp.$1, "p");
assertEq(RegExp.$2, "");
"x\ny\n".replace(/(^\n*)/, "");
assertEq(RegExp.$1, "");
assertEq(RegExp.$2, "");

View File

@ -2465,16 +2465,18 @@ str_replace_regexp_remove(JSContext *cx, CallArgs args, HandleString str, RegExp
lazyIndex = lastIndex;
lastIndex = startIndex;
if (match.isEmpty())
startIndex++;
/* Non-global removal executes at most once. */
if (!re.global())
break;
if (match.isEmpty())
startIndex++;
}
/* If unmatched, return the input string. */
if (!lastIndex) {
if (startIndex > 0)
cx->regExpStatics()->updateLazily(cx, stableStr, &re, lazyIndex);
args.rval().setString(str);
return true;
}