New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 740458 link

Starred by 3 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Jul 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 2
Type: Bug



Sign in to add a comment

Different results of Pattern.test with same input values

Reported by morphs.d...@gmail.com, Jul 10 2017

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36

Steps to reproduce the problem:
var pattern = /^([a-z0-9\-_]+)$/gi;
var input = 'Hello-__----__-__-123123123fwefwfgawgf123';

pattern.test(input);

What is the expected behavior?
The test function should return true.

What went wrong?
The test function returns true and false alternating.

Did this work before? N/A 

Chrome version: 59.0.3071.115  Channel: stable
OS Version: Ubuntu 17.04
Flash Version: -
 
JS Bug.PNG
40.5 KB View Download
The bug is also reproducable in FireFox 54.0 (64-Bit), also on Ubuntu 17.04 64-Bit.
My fault: It works as intended as explained here: https://stackoverflow.com/a/1520853/2560143
Cc: brajkumar@chromium.org
Labels: Needs-Feedback
Unable to reproduce this issue on Ubuntu 14.04 using chrome latest stable #59.0.3071.115 by following steps mentioned in the original comment. By entering the script in the console the test function returned true.

Reporter@ Attaching screen-shot for reference, Could you please confirm is this is the expected behavior for this issue? 
740458.png
21.6 KB View Download
The problem was that with option /g after the successfull search the lastIndex of the pattern is at the end of input, which then leads to a failed search when applying test() a second time, which also leads to resetting lastIndex to 0, causing alternating resuls.  
Redefining the pattern, as you did, also resets the lastIndex to 0.
@brajkumar It's reproducable if you set the two variables only one time and repeat executing the pattern.test function. But as yasmin.b already mentioned this was caused by the global flag and it's the expected behavior according to stackoverflow: https://stackoverflow.com/a/1520853/2560143
Project Member

Comment 6 by sheriffbot@chromium.org, Jul 11 2017

Labels: -Needs-Feedback
Thank you for providing more feedback. Adding requester "brajkumar@chromium.org" to the cc list and removing "Needs-Feedback" label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Comment 7 by rtoy@chromium.org, Jul 11 2017

Status: WontFix (was: Unconfirmed)
Based on the c#2 and c#5, this is working as intended.

Closing (WontFix WAI)

Sign in to add a comment