« Bugzilla Issues Index
#2617 — 21.2.5.7 RegExp.prototype.replace: Call replacer function after all matches were found
- bug_id:
2617
- creation_ts:
2014-04-10 05:47:00 -0700
- short_desc:
21.2.5.7 RegExp.prototype.replace: Call replacer function after all matches were found
- delta_ts:
2014-04-29 22:09:42 -0700
- product:
Draft for 6th Edition
- component:
technical issue
- version:
Rev 23: April 5, 2014 Draft
- rep_platform:
All
- op_sys:
All
- bug_status:
RESOLVED
- resolution:
FIXED
- priority:
Normal
- bug_severity:
normal
- everconfirmed:
true
- reporter:
André Bargull
- assigned_to:
Allen Wirfs-Brock
- commentid:
7644
- comment_count:
0
- who:
André Bargull
- bug_when:
2014-04-10 05:47:02 -0700
21.2.5.7 RegExp.prototype.replace ( string, replaceValue ):
For ECMAScript 5 and browser compatibility, RegExp.prototype.replace needs to call the replacer function after all matches were found.
Test case: https://github.com/mozilla/gecko-dev/blob/master/js/src/tests/ecma_5/String/replace-updates-global-lastIndex.js
Simplified test case:
---
r = /x/g;
'0x2x4x6x8'.replace(r, function(){ print(r.lastIndex) })
---
Expected: Prints four times 0
Actual: Prints 2, 4, 6, 8
Tested in: SpiderMonkey, JSC, V8, IE11, Nashorn
- commentid:
7647
- comment_count:
1
- who:
André Bargull
- bug_when:
2014-04-10 06:15:05 -0700
Different test case which is currently broken when following spec algorithm:
---
var g_rx = /test/g;
"test-string".replace(g_rx, function() { g_rx.lastIndex = 0; return "a" });
---
Expected: "a-string"
Actual: attempt to retrieve invalid substring from [start=4, end=0]
- commentid:
7725
- comment_count:
2
- who:
Allen Wirfs-Brock
- bug_when:
2014-04-14 12:57:40 -0700
fixed in rev24 editor's draft
- commentid:
7998
- comment_count:
3
- who:
Allen Wirfs-Brock
- bug_when:
2014-04-29 22:09:42 -0700
fixed in rev24