Closed Bug 218432 Opened 22 years ago Closed 22 years ago

lastIndex problem after String.search()

Categories

(Core :: JavaScript Engine, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: jophof007, Assigned: rogerl)

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 myString = new String("Go to DevGuru.com") rExp = /devguru.com/gi; results = myString.search(rExp) document.write(results + " lastindex " + rExp.lastIndex); Script gives 17 in IE and 0 in Mozilla for the lastIndex. Also problemes with lastindex on other pages. Reproducible: Always Steps to Reproduce: 1. 2. 3. Expected Results: lastindex 17
Actually, Mozilla is correct here, not IE. Here is the specification of the .search() method from the spec for the JavaScript language. This spec is available at http://www.mozilla.org/js/language/E262-3.pdf : --- 15.5.4.12 String.prototype.search (regexp) If regexp is not an object whose [[Class]] property is "RegExp", it is replaced with the result of the expression new RegExp(regexp). Let string denote the result of converting the this value to a string. The value string is searched from its beginning for an occurrence of the regular expression pattern regexp. The result is a number indicating the offset within the string where the pattern matched, or –1 if there was no match. NOTE This method ignores the lastIndex and global properties of regexp. The lastIndex property of regexp is left unchanged. NOTE The search function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. --- Note the spec specifically states the method is not to change |lastIndex|.
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → INVALID
Summary: lastindex problem → lastIndex problem after String.search()
Marking Verified. jophof007@yahoo.com: thank you for this report; you raise a valid point. It's not good when different browsers perform differently on the same code. That is why we hope all browsers will follow the specs -
.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.