Closed Bug 591318 Opened 14 years ago Closed 14 years ago

Invalid String.prototype.replace with string search value: "a".replace("$", "\\$") returns "a\$"

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: mayhemer, Unassigned)

Details

Expected result is "a". Also: "a".replace(".", "\\$")) returns "\$", "a".replace("^", "\\$")) returns "\$a" The first argument is clearly taken as regexp. This cannot be reproduced with the second argument different from "\\$". This bug appears in Firefox 4 beta 4, was not present in Firefox 4 beta 3. I don't have narrower regression range at the moment. Workaround: "a".replace(/\$/g, "\\$") returns "a" as expected.
The first argument to the String.prototype.replace is *not* automatically converted to a regular expression, per ECMAScript 5th edition section 15.5.4.11 paragraph two: "If searchValue is not a regular expression, let searchString be toString(searchValue) and search string for the first occurrence of searchString." Also see recent bug 587366. Thanks for filing, though!
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
Summary: "a".replace("$", "\\$") returns "a\$" → Invalid String.prototype.replace with string search value: "a".replace("$", "\\$") returns "a\$"
Resolution: INVALID → WORKSFORME
Er yeah, whoops... that was the bug we fixed. Thanks for the correction Alice0775 White.
You need to log in before you can comment on or make changes to this bug.