Javascript undefined behavior with string.replace
- by epochwolf
I've been messing around with string.replace and I noticed something very odd with Webkit and Firebug's javascript consoles.
I can repeat this behavior in a blank browser window. (Look at the first and last lines)
>>> "/literature?page=".replace(/page=/i, "page=2")
"/literature?page="
>>> "/literature?page=".replace("page=", "page=2")
"/literature?page=2"
>>> "/literature?page=".replace(/page=/, "page=2")
"/literature?page=2"
>>> "/literature?page=".replace(/page=/i, "page=2")
"/literature?page=2"
Just so nobody thinks I mistyped something, here are screenshots.
Firebug (3.0.14)
Webkit (Latest nightly as of this post's creation.)