Different results of Pattern.test with same input values
Reported by
morphs.d...@gmail.com,
Jul 10 2017
|
||||
Issue descriptionUserAgent: 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: -
,
Jul 10 2017
My fault: It works as intended as explained here: https://stackoverflow.com/a/1520853/2560143
,
Jul 11 2017
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?
,
Jul 11 2017
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.
,
Jul 11 2017
@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
,
Jul 11 2017
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
,
Jul 11 2017
Based on the c#2 and c#5, this is working as intended. Closing (WontFix WAI) |
||||
►
Sign in to add a comment |
||||
Comment 1 by morphs.d...@gmail.com
, Jul 10 2017