RegExp search bug

A Listing of Confirmed Scripting Bugs and Anomalies - Open to all but only moderators can post

Moderators: xbytor, DavideBarranca, Paul MR

User avatar
Kukurykus
Posts: 225
Joined: Mon Jul 25, 2016 12:36 pm

RegExp search bug

Post by Kukurykus »

Following code should alert 'True' twice - it works corectly in google.com console (ctrl+shift+i) and labs.codecademy.com (choose javascript):

Code: Select all

var arr = ['a.jpg', 'b.jpg'], reg = /\.jpg$/i

for(var i = 0; i < arr.length; i++) {
alert(arr[i].search(reg) != -1)
}
In ESTK 1.0 (CS2) and 3.6 (CS5.1) it displays 'True" only at first time, at sectond it's 'False'
When I applied modification to that code it worked correctly so like in mentioned sites.

Code: Select all

var arr = ['a.jpg', 'b.jpg']

for(var i = 0; i < arr.length; i++) {
alert(arr[i].search(/\.jpg$/i) != -1)
}
or

Code: Select all

var arr = ['a.jpg', 'b.jpg'], reg = /\.jpg$/i

for(var i = 0; i < arr.length; i++) {
alert(arr[i].search(reg) != -1)
reg = /\.jpg$/i
}
I wanted originally to post it in viewtopic.php?f=65&t=6605&sid=fd91ebfa8 ... 7949a9f0e8 but that RegExp search bug is a little different.

I found it analysing Mike Hale code (still I have no idea how that worked for him, if he tested it of course, because that was only answer to someone problem). When you'll check it just replace mask variable in 14th line:

Code: Select all

if (procFiles[i].fullName.search([b]mask[/b]) != -1) allFiles.push(procFiles[i]); // otherwise only those that match mask
with RegExp /\.(jpg|tif|psd|bmp|gif|png|)$/i from 2nd line

Here's that topic (look for his answer from 2013-07-02 13:49): https://forums.adobe.com/thread/1246514


Post Scriptum. I found that from JavierAroche answer-link to this topic https://www.ps-scripts.com/viewtopic.php?f=66&t=24364, after I replied my answer-code which after few posts (of others meantime) is still not accepted by moderator or just vanished(?)

pixxxelschubser
Posts: 26
Joined: Mon Aug 01, 2016 8:59 pm

Re: RegExp search bug

Post by pixxxelschubser »

Please try:

Code: Select all

var arr = ['a.jpg', 'b.jpg'];
var reg = /\.jpg$/i;
for(var i = 0; i < arr.length; i++) {
alert(arr[i].search(reg) != -1)
}

User avatar
Kukurykus
Posts: 225
Joined: Mon Jul 25, 2016 12:36 pm

Re: RegExp search bug

Post by Kukurykus »

I assume it works for you? I just tried and the result is the same like before (CS2 and CS5.1).
In your code it differs from my version that variable for RegEx is in next line if that had to be solution.

Possibly in higher CS it works correctly finally. Mike Hale posted it when CC was realsed (2013-07-03).
What was version of Photoshop and ExtendScript you tested it in?

pixxxelschubser
Posts: 26
Joined: Mon Aug 01, 2016 8:59 pm

Re: RegExp search bug

Post by pixxxelschubser »

You are totally right.
I mix reluctant different types of variables.

But it seems to be a bug in ESTK 1, and 2 and till version 3.6.02 (I haven't a CS6 for testing)

With ESTK (CC) 4.0.0.1 Extend Script 4.5.5 the result is ok now.

Code: Select all

var arr = ['a.jpg', 'b.jpg'];
var reg = /\.jpg$/i;
for(var i = 0; i < arr.length; i++) {
alert(arr[i] + ".search(" + reg + ") --> result --> " + (arr[i].search(reg) != -1))
}
The result is as expected »true« for both parts of array.

Regards