Closed Bug 202564 Opened 22 years ago Closed 22 years ago

JavaScript regexp matches same text in two places

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

VERIFIED DUPLICATE of bug 85721

People

(Reporter: drbrain-bugzilla, Assigned: rogerl)

References

()

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4b) Gecko/20030411 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4b) Gecko/20030411 The Regex in the URL has 'Buckley' in the 4th group, when it should be null. Both IE (same code) and Ruby get this right (slightly modified code). Reproducible: Always Steps to Reproduce: 1. Click URL Actual Results: 'Buckley' is displayed in an alert box Expected Results: nothing should be displayed in the alert box (no text)
var re = /(?:(.+), )?(.+), (..) to (?:(.+), )?(.+), (..)/ var str = "Seattle, WA to Buckley, WA" var arr = re.exec(str); According to Perl, the correct match array should be: arr[0] = "Seattle, WA to Buckley, WA" arr[1] = "" arr[2] = "Seattle" arr[3] = "WA" arr[4] = "" arr[5] = "Buckley" arr[6] = "WA" SUMMARY using the shorthand |str| for the 0th match elt Perl [str, "", "Seattle", "WA", "", "Buckley", "WA"] IE6 [str, "", "Seattle", "WA", "", "Buckley", "WA"] JS 85721 [str, , "Seattle", "WA", , "Buckley", "WA"] JS tip [str, "", "Seattle", "WA", "Buckley", "Buckley", "WA"] "JS 85721" refers to the JS tip with the patch for bug 85721 applied. Note that the empty-string matches one gets in Perl and IE6 match as |undefined| here instead of the empty string. This is because in ECMA, regexp backreferences must hold |undefined| if not used. See bug 123437. So modulo this difference in convention between Perl/IE and ECMA/JS, this is one more bug that will be fixed in the big RegExp rewrite underway in bug 85721. I will create a testcase from this example, add it to the testsuite, and dupe this bug against bug 85721.
Testcase added to JS testsuite: mozilla/js/tests/ecma_3/RegExp/regress-202564.js Currently failing in the JS tip, but passing in the JS 85721 shell and in Rhino, where the patch for bug 85721 has already gone in. *** This bug has been marked as a duplicate of 85721 ***
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → DUPLICATE
Summary: Javascript Regex matches same text in two places → JavaScript regexp matches same text in two places
Marking Verified. Eric, thank you for this report. You have been cc'ed on the other bug so you can follow progress on this issue -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.