[Workaround found] filter with/without returns wrong results

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1549
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

[Workaround found] filter with/without returns wrong results

Post by [-hh] » Sun Jun 05, 2016 5:43 pm

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.
Last edited by [-hh] on Tue Jun 07, 2016 3:18 pm, edited 1 time in total.
shiftLock happens

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3977
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: filter with/without returns wrong results

Post by jacque » Mon Jun 06, 2016 5:04 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1549
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: filter with/without returns wrong results

Post by [-hh] » Mon Jun 06, 2016 6:07 pm

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.
shiftLock happens

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: filter with/without returns wrong results

Post by Thierry » Mon Jun 06, 2016 6:29 pm

[-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
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1549
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: filter with/without returns wrong results

Post by [-hh] » Mon Jun 06, 2016 7:41 pm

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.
shiftLock happens

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1549
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: filter with/without returns wrong results

Post by [-hh] » Tue Jun 07, 2016 3:17 pm

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.
shiftLock happens

Post Reply

Return to “Bug Triage”