Closed
Bug 402046
Opened 17 years ago
Closed 17 years ago
RegExp test() returns inconsistent results
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: jay, Unassigned)
Details
Attachments
(1 file)
538 bytes,
text/html
|
Details |
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8
When doing a javascript regexp test, it can return true once, but if run again it can return false.
Reproducible: Always
Steps to Reproduce:
1. See attached testcase
2. Enter a value containing character other than letters or numbers
3. Click the "Test Value" link
4. Click it again.
Actual Results:
first time, you get the error message, but the second time you do not.
Expected Results:
Gives the error message each time.
Reporter | ||
Comment 1•17 years ago
|
||
Updated•17 years ago
|
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Updated•17 years ago
|
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → DUPLICATE
Comment 3•17 years ago
|
||
I can reproduce with the command-line js shell, using:
function f(s) { return /[^A-Z0-9]/gi.test(s); }
f("@");
f("@");
It returns true the first time and false the second time.
This might be related to bug 98409, which is widely considered to be a bug in the ECMAScript 3 specification: you don't get a new instance of the regexp object each time f() runs.
This only happens if the regular expression has the 'g' flag. I don't know whether it's intentional that the 'g' flag affects the .test() function; http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:RegExp:test doesn't mention it.
js> r = /a/g;
/a/g
js> s = "aba";
aba
js> r.test(s);
true
js> r.test(s);
true
js> r.test(s);
false
If that behavior of test() is correct and intentional, then this is a dup of bug 98409.
Comment 4•17 years ago
|
||
Explanation in bug 225408 comment 2.
Updated•17 years ago
|
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•