Page 1 of 1

Regex bug in internal viewer

Posted: 01 Jan 2011, 13:34
by mdruiter
I encountered a weird bug when searching for a regular expression in the internal viewer.

Try this:
- save this (or enclosed) file:

Code: Select all

1 XXXXXX_CCCCCCCCCC

3 XXXXXX_AAAAAAAA
4 XXXXXX_BBBBBBBB

6 XXXXXX_AAAAAAAA XXXXXX_BBBBBBBB
- open it in the internal viewer
- search for this regular expression (forward, not whole word, case insensitive):

Code: Select all

XXXXXX_AAAAAAAA|XXXXXX_BBBBBBBB|XXXXXX_CCCCCCCCCC|YYY_DDDDDDDDDD|YYY_EEEEEEEEEE|YYY_FFFFFFFF|YYY_GGGGGGGGGGG|YYY_HHHHHHHH|ZZZ_YYY_IIIIIIII|YYY_JJJJJJJJJ|YYY_KKKKKKKKK|YYY_LLLL|YYY_MMMMMMMMMM
- press F3 to find the next occurrence
- press F3 to find the next occurrence

After finding line 1, line 4 is found and highlighted, and then the last part of line 6 (both XXXXXX_BBBBBBBB. :?
I would expect to find XXXXXX_AAAAAAAA as well, in lines 3 and 6! :(

If I press Shift+F3 to search backwards, all occurrences are found.

Re: Regex bug in internal viewer

Posted: 01 Jan 2011, 19:01
by Ether
I can confirm this, though I have no idea what causes this. The bug seems to manifest only when all the alternatives contain an underscore and only when the expression is of certain length or longer.

Re: Regex bug in internal viewer

Posted: 02 Jan 2011, 23:42
by Petr Solin
Thanks for finding this bug! I have fixed it and we will it in next beta version. I expect it is not critical.

It was in operators precedence (+ is above &):
original: #define NEXT(p) (((*((p)+1)&0377)<<8) + *((p)+2)&0377)
fixed: #define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
(original NEXT cannot never give result over 255 which was neccessary it this case)

Regex bug in Find too

Posted: 05 Jan 2011, 10:40
by mdruiter
I found a very similar thing in Find Files and Directories.

Try this:
- save this (or enclosed) file:

Code: Select all

1 N_PL
- in that directory, press Ctrl+F
- search for files containing this regular expression (not whole word, case insensitive):

Code: Select all

XXXXXXXX|XXXX|XXXXXX|N_PL|XXXXXXX|XXXXXXX|XXXXX|XXXXXXXXXXXXX|XXXXXXXXXXXXX|XXXXXX|XXXXXXXXXXX|XXXXXXXXXXXXX|XXXXXXX|XXXXXXX|XXXXXXX|XXXXXXX|XXXXXXXXX|XXXXXXXX|XXXXXXXX|XXXXXXXX
The file will not be found! :(
If I remove the last character of the regular expression, the file is found as expected.

I think not finding files is a little more critical than not finding parts in a file.

Re: Regex bug in internal viewer

Posted: 06 Jan 2011, 08:07
by Petr Solin
Thanks for report! Find uses the same library, so it is fixed too. I have found this library also in Renamer and FTP Search plugins, but this bug has already been fixed there (unfortunately this fix has not been propagated back to Salamander).

Re: Regex bug in internal viewer

Posted: 06 Jan 2011, 10:09
by mdruiter
Great! I'll wait! :-)