If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

multiple calls to regex.test with global flag returns different results

VERIFIED DUPLICATE of bug 98409

Status

()

Core
JavaScript Engine
--
minor
VERIFIED DUPLICATE of bug 98409
14 years ago
14 years ago

People

(Reporter: jeff, Unassigned)

Tracking

Trunk
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

14 years ago
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

14 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

14 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
Last Resolved: 14 years ago
Resolution: --- → DUPLICATE

Comment 3

14 years ago
Verified duplicate -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.