Closed
Bug 502569
Opened 16 years ago
Closed 15 years ago
Excute a same function with RegExp inside doesn't always return the same result.
Categories
(Firefox :: General, defect)
Tracking
()
RESOLVED
INCOMPLETE
People
(Reporter: shijistar, Unassigned)
Details
(Whiteboard: [CLOSEME 2011-1-1])
Attachments
(1 file, 1 obsolete file)
|
850 bytes,
text/html
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)
I just use a RegExp object to test a pass-in string, I call this method several times with a same parameter, but I get a alternative result each time: true, false, true, false....
Reproducible: Always
Steps to Reproduce:
1.Create a blank html page.
2.Define this method between <head> elements.
function isNum(value){
var reg=/^[\d]*$/gi;
return reg.test(value);
}
Very simple method.
3.Call this method several times after the page is loaded, with a same parameter "111" for example.
Actual Results:
true, false, true, false...
The results are always alternative true and false.
Expected Results:
true, true... Always true.
If I remove the "g" flag of the RegExp object, or call the reg.test() directly, the result will be all right, i.e. always true.
This problem exists both on Firefox 2 and Firefox 3.5. I didn't test on other versions. I use the default theme and my os is Windows XP SP2.
The build configuration is:
about:buildconfig
Source
Built from http://hg.mozilla.org/releases/mozilla-1.9.1/rev/a625a31a0ad1
Build platform
target
i686-pc-mingw32
Build tools
Compiler Version Compiler flags
cl 14.00.50727.762 -TC -nologo -W3 -Gy -Fdgenerated.pdb -DNDEBUG -DTRIMMED -Zi -UDEBUG -DNDEBUG -GL -wd4624 -wd4952 -O1
cl 14.00.50727.762 -GR- -TP -nologo -Zc:wchar_t- -W3 -Gy -Fdgenerated.pdb -DNDEBUG -DTRIMMED -Zi -UDEBUG -DNDEBUG -GL -wd4624 -wd4952 -O1
Configure arguments
--enable-application=browser --enable-update-channel=release --enable-update-packaging --enable-jemalloc --enable-official-branding
Keywords: regression
Keywords: regression
Comment 1•15 years ago
|
||
Reporter, are you still seeing this issue with Firefox 3.6.12 or later in safe mode? If not, please close. These links can help you in your testing.
http://support.mozilla.com/kb/Safe+Mode
http://support.mozilla.com/kb/Managing+profiles
Also, please consider using the most recent Firefox 4 beta build, your bug may be resolved there.
Whiteboard: [CLOSEME 2011-1-1]
Same issue in Firefox 3.6.13. From a cursory web search this may be "valid according to spec" behavior for global RegExp variables. However within a function as a local variable, this might not be valid.
In order to use the /g flag, was able to add lastIndex = 0 to get it to work.
Workaround:
function isNum(value){
var reg=/^[\d]*$/gi;
reg.lastIndex = 0;
return reg.test(value);
}
Comment 3•15 years ago
|
||
No reply, INCOMPLETE. Please retest with Firefox 3.6.13 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Resolution: --- → INCOMPLETE
I retest in Firefox 3.6.13 and with a new profile for second time, however the same issue still exists.
It's true that it can be fixed by setting the lastIndex = 0. However I wonder that if it can be resolved by Firefox in background, because I test the same case in all other browsers and none of them have the same behavior (Opera also fixes this issue in the lastest version, v11.00 build 1156).
Other browsers will reset all states whenever I create a new RegExp object, no matter using the flag of "g" or not.
I test in Firefox 3.6.13 and using a new profile for second time, and the same issue still exists.
It's true that it can be fixed by setting the lastIndex = 0. However I wonder that if it can be resolved by Firefox in background, because I test the same case in all other browsers and none of them have the same behavior (Opera also fixes this issue in the lastest version, v11.00 build 1156).
Other browsers will reset all states whenever I create a new RegExp object, and no matter using the flag of "g" or not.
The test page can be executed directly in Firefox to reproduce the issue or compare with other browsers.
The test page can be executed directly in Firefox to reproduce the issue or
compare with other browsers.
This version of test page is more friendly, so make the previous test page obsolete.
Attachment #506289 -
Attachment is obsolete: true
You need to log in
before you can comment on or make changes to this bug.
Description
•