Closed
Bug 294971
Opened 20 years ago
Closed 20 years ago
String.replace on document.location produces odd results
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: eph1v3t8-list6699, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
If you set a variable str equal to document.location, and then set a second
variable str2 equal to the result of str.replace(...), two strange things happen:
1) str2 is undefined
2) Firefox tries to go to a page whose URL is the regular expression given to
String.replace.
Here's some HTML/javascript that shows the problem:
<html>
<head>
<script>
function bug() {
var str = document.location;
alert("str="+str);
var re = new RegExp("/&/g");
var str2 = str.replace(re, "&");
// At this point, Firefox tries to go to file /&/g.
}
</script>
</head>
<body onload="bug()">
</body>
</html>
Reproducible: Always
Comment 1•20 years ago
|
||
The DOM level 0 location object (really window.location, but because of browser war interop bugs, also available at document.location) has a replace method that loads the given argument URL over top of the current session history entry. If you want window.location as a string, use window.location.href or window.location.toString() or String(window.location). /be
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•