Closed Bug 103351 Opened 23 years ago Closed 23 years ago

'abc'.replace(undefined, 'Z') should be 'abc', not 'Zabc'

Categories

(Core :: JavaScript Engine, defect)

x86
All
defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla0.9.9

People

(Reporter: pschwartau, Assigned: khanson)

Details

(Keywords: js1.5)

Attachments

(1 file)

This bug grew out of bug 83293. 

Bug 83293 addressed this: 'abc'.replace('', 'Z') should be 'Zabc'
SpiderMonkey gave no return.

Here we consider this:    'abc'.replace(undefined, 'Z') should be 'abc'
SpiderMonkey returns 'Zabc'

Both bugs derive from ECMA-262 Final Edition, Section 15.5.4.11
String.prototype.replace (searchValue, replaceValue)  

The Final Edition states that searchValue, if not of type RegExp,
should be converted to String(searchValue), and the replace() method
should then search for the first occurrence of this string and replace it.

So, since String(undefined) == 'undefined', and there is no
occurrence of 'undefined' in the string 'abc', we should have:

             'abc'.replace(undefined, 'Z') == 'abc'
Note: the ECMA Final Edition differs vis-a-vis the ECMA Final Draft on the
syntax for the replace() method, and is inconsistent with the Final Edition
syntax for the related methods search(), match() of String.prototype
in the case where searchValue is not of type RegExp. See bug 83293 for details.

The testcase for this bug is

              js/tests/ecma_3/String/regress-83293.js
Keywords: js1.5
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.7
Retargeting for 9.8.
Target Milestone: mozilla0.9.7 → mozilla0.9.8
targeting 9.9.
Target Milestone: mozilla0.9.8 → mozilla0.9.9
Attached patch proposedSplinter Review
Hoping kenton doesn't mind the intrusion, I was working on related stuff and
believe simply taking out the special handling for 'undefined' will do the
job...
Comment on attachment 68823 [details] [diff] [review]
proposed

Patch is not up to date with respect to the cvs trunk, but no worries -- just
update before you commit, no need for another patch.  sr=brendan@mozilla.org.

/be
Attachment #68823 - Flags: superreview+
Comment on attachment 68823 [details] [diff] [review]
proposed

r=khanson
Attachment #68823 - Flags: review+
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Marking Verified FIXED. The testcase above, ecma_3/String/regress-83293.js,
now passes in the debug/optimized JS shell on WinNT, Linux, and Mac9.1.
Status: RESOLVED → VERIFIED
Flags: testcase?
Flags: testcase? → testcase+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: