If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

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

VERIFIED FIXED in mozilla0.9.9

Status

()

Core
JavaScript Engine
VERIFIED FIXED
16 years ago
13 years ago

People

(Reporter: Phil Schwartau, Assigned: Kenton Hanson (gone))

Tracking

({js1.5})

Trunk
mozilla0.9.9
x86
All
js1.5
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

1.42 KB, patch
Kenton Hanson (gone)
: review+
brendan
: superreview+
Details | Diff | Splinter Review
(Reporter)

Description

16 years ago
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'
(Reporter)

Comment 1

16 years ago
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
(Assignee)

Updated

16 years ago
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.7
(Assignee)

Comment 2

16 years ago
Retargeting for 9.8.
Target Milestone: mozilla0.9.7 → mozilla0.9.8
(Assignee)

Comment 3

16 years ago
targeting 9.9.
Target Milestone: mozilla0.9.8 → mozilla0.9.9

Comment 4

16 years ago
Created attachment 68823 [details] [diff] [review]
proposed

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+
(Assignee)

Comment 6

16 years ago
Comment on attachment 68823 [details] [diff] [review]
proposed

r=khanson
Attachment #68823 - Flags: review+

Comment 7

16 years ago
Fix checked in.
Status: ASSIGNED → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → FIXED
(Reporter)

Comment 8

16 years ago
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

Updated

13 years ago
Flags: testcase?

Updated

13 years ago
Flags: testcase? → testcase+
You need to log in before you can comment on or make changes to this bug.