RegExp lastIndex not set after test method call

RESOLVED FIXED in Firefox 53

Status

()

defect
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: github, Assigned: arai)

Tracking

50 Branch
mozilla53
Points:
---

Firefox Tracking Flags

(firefox53 fixed)

Details

Attachments

(1 attachment)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36 OPR/41.0.2353.56

Steps to reproduce:

// I ran this JavaScript:

var regExp = /.*x?/g;
regExp.test('12345');
console.log(regExp.lastIndex);


Actual results:

regExp.lastIndex should be 5 after test method call. It is in all browsers except Firefox.


Expected results:

regExp.lastIndex is 0
Component: Untriaged → JavaScript: Standard Library
Product: Firefox → Core
Status: UNCONFIRMED → NEW
Ever confirmed: true
https://dxr.mozilla.org/mozilla-central/source/js/src/irregexp/RegExpParser.cpp#1840-1863

Apparently this optimization should be more restricted.
If trailing pattern can match empty string, we shouldn't strip leading ".*"

or, just that we shouldn't strip it if `global || sticky`
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
We just checked the length of the pattern to see there's other pattern after ".*",
and relied on the pattern after that matches to correct position.
but it doesn't match because the pattern could match to empty string.

So, stopped applying the optimization for test with global/sticky.
using global/sticky RegExp for test should be unusual, so this won't hurt performance for common case.
Attachment #8816754 - Flags: review?(hv1989)
Comment on attachment 8816754 [details] [diff] [review]
Do not strip leading .* pattern in RegExp.prototype.test with global/sticky flags.

Review of attachment 8816754 [details] [diff] [review]:
-----------------------------------------------------------------

Makes sense. Thanks for the testcases!
Attachment #8816754 - Flags: review?(hv1989) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/82aeade4d0073cd0c2da2d61543fe0a50430cfbb
Bug 1322035 - Do not strip leading .* pattern in RegExp.prototype.test with global/sticky flags. r=h4writer
https://hg.mozilla.org/mozilla-central/rev/82aeade4d007
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
You need to log in before you can comment on or make changes to this bug.