Closed
Bug 225408
Opened 21 years ago
Closed 21 years ago
multiple calls to regex.test with global flag returns different results
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: jemminger, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20031007 Firebird/0.7
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20031007 Firebird/0.7
using a regex with global flag, two identical calls to test() returns both true
and false:
<script type="text/javascript">
function isBuggy(s) {
return !/^foo$/gi.test(s);
}
alert(isBuggy("foo")); // returns false
alert(isBuggy("foo")); // returns true
</script>
Reproducible: Always
Steps to Reproduce:
<script type="text/javascript">
function isBuggy(s) {
return !/^foo$/gi.test(s);
}
alert(isBuggy("foo")); // returns false
alert(isBuggy("foo")); // returns true
</script>
Actual Results:
false, true
Expected Results:
false, false
not a critical problem, since removing the global flag corrects it, and test()
only returns the first match anyway
Comment 1•21 years ago
|
||
Confirmed on
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031122
Firebird/0.7+
-> JS Engine
Assignee: blake → general
Status: UNCONFIRMED → NEW
Component: General → JavaScript Engine
Ever confirmed: true
Product: Firebird → Browser
QA Contact: PhilSchwartau
Version: unspecified → Trunk
Comment 2•21 years ago
|
||
Sorry, but Mozilla/Firebird is following the ECMA-262 spec for the language
on this. The spec is available at http://www.mozilla.org/js/language/.
In Edition 3, see Section 15.10.6.3 (referencing Section 15.10.6.2).
I had thought that IE6 was in compliance on this, but apparently not.
See details, examples and discussion at bug 98409 and bug 112376.
The point is, when the global flag is set, |regex.lastIndex| is supposed
to increment so as to reflect the match last performed; the next match is
supposed to begin from there. Therefore if the last match exhausted the
end of the test string, the next match begins beyond the string and
returns |null|.
*** This bug has been marked as a duplicate of 98409 ***
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•