Closed Bug 877880 Opened 7 years ago Closed 5 years ago

String .match() for non-global regexp does not respect lastIndex

Categories

(Core :: JavaScript: Standard Library, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 887016

People

(Reporter: sstangl, Unassigned)

Details

By ECMA-262 15.5.4.10, if a non-global regexp |rx| is given as argument to s.match(), the return value is the result of calling |rx.exec(s)|.

Meanwhile, exec() is defined by 15.10.6.2 to begin the match from and update the regexp |lastIndex| property.

Our current implementation in DoMatchLocal() always begins the match from a lastIndex of 0, and does not update the lastIndex property.
I should point out that this only affects regular expressions with our "sticky" extension. I wonder if anyone even uses that.
There's at least one other es5-blocking bug -- bug 501739 -- complaining about our not updating, or updating, lastIndex.  When I looked at it and read spec language awhile, I thought what we were doing was right.  Although, I was never particularly confident of this assessment, so I never closed the bug as WFM or similar.  Also it seems there was some patchwork happening there from non-regular SpiderMonkey hackers, it seems, that I reviewed and noted had definite spec inconsistencies.

Our "sticky" extension is probably semi-lightly used among extension authors, and I wouldn't be surprised if the browser uses it a little, too.  It's nice for things like iterating through a string and matching stuff along the way, as I recall.  Given it's an extension, technically whatever we do for sticky-ful RegExps is totally up to us, I think.  I have the faintest recollection of impedance mismatches/un-intuitivenesses between the global/sticky flags when considering this code, a long while back, but I don't remember anything in detail.
Assignee: general → nobody
Component: JavaScript Engine → JavaScript: Standard Library
bug 887016 will implement proper match/search/replace/split.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 887016
You need to log in before you can comment on or make changes to this bug.