Page 1 of 1

[Workaround found] filter with/without returns wrong results

Posted: Sun Jun 05, 2016 5:43 pm
by [-hh]
If the input string for "filter" contains a left square bracket, then the results are wrong:

Simple example.

Code: Select all

local t="abcdefg"

on mouseUp
  repeat for each char c in t
    put cr & c &"[" after s
  end repeat
  put char 2 to -1 of s into myInput
  -- try also patterns other than "a["
  if the shiftkey is down then
    filter myInput without "a[" --> returns myInput (the full string)
  else filter myInput with "a[" --> returns empty
  put myInput into fld "OUT"
end mouseUp
For that input
= filter <inputVar> with <pattern> returns always empty, no matter the pattern
= filter <inputVar> without <pattern> returns always the full <inputVar>, no matter the pattern

Never filter filenames if any of the paths contains a left square bracket ...

Tested to be faulty with LC 6.7.11/7.1.4/8.1.0-dp1.
Didn't test other filtering/matching methods.

Re: filter with/without returns wrong results

Posted: Mon Jun 06, 2016 5:04 pm
by jacque
The filter will try to match the whole line. To match partial lines it needs the wildcard character. Change "a[" to "a[*".

Edit : never mind, I see the string is already a complete line. It should work.

Re: filter with/without returns wrong results

Posted: Mon Jun 06, 2016 6:07 pm
by [-hh]
Presumably they use internally a regex pattern so that "[" in the input string gets a special meaning.

I used this kind of filter for a list of filenames when a new one was added to the list, so I was always filtering with a "full line" pattern.
Never had problems until the first "[" in a filename.

Re: filter with/without returns wrong results

Posted: Mon Jun 06, 2016 6:29 pm
by Thierry
[-hh] wrote:Presumably they use internally a regex pattern so that "[" in the input string gets a special meaning.

I used this kind of filter for a list of filenames when a new one was added to the list, so I was always filtering with a "full line" pattern.
Never had problems until the first "[" in a filename.
Hallo Hermann,

Same problem with LC 6.7.9.

I did try with 'a{' or 'a(' and then it works as expected.

Maybe a good time for a bug report?

Thierry

Re: filter with/without returns wrong results

Posted: Mon Jun 06, 2016 7:41 pm
by [-hh]
Done: # 17802.

Hi Thierry,

hopefully this doesn't affect also your specials with matchtext etc?
Maybe it's time for a filter/regex external by you?

H.

Re: filter with/without returns wrong results

Posted: Tue Jun 07, 2016 3:17 pm
by [-hh]
Panos@LiveCode found the following workaround for the current situation:

Replace "[" with "[[]" in the pattern string.

That is, in my example above, where the pattern is a full line, the workaround is:
filter myInput with "a[[]" or filter myInput without "a[[]" respectively.