discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in NSPredicate?


From: Richard Frith-Macdonald
Subject: Re: Bug in NSPredicate?
Date: Tue, 4 Mar 2014 06:34:33 +0000

On 3 Mar 2014, at 16:12, Mathias Bauer <mathias_bauer@gmx.net> wrote:

> Hi dear list members,
> 
> IMHO the following code in NSPredicate.m is wrong:
> 
> (line 944 ff.)
> 
>>        NSString *regex;
>> 
>>        /* The right hand is a pattern with '?' meaning match one character,
>>         * and '*' meaning match zero or more characters, so translate that
>>         * into a regex.
>>         */
>>        regex = [rightResult stringByReplacingOccurrencesOfString: @"*"
>>                                                       withString: @".*"];    
>> // wrong!
>>        regex = [regex stringByReplacingOccurrencesOfString: @"?"
>>                                                 withString: @".?"];          
>> // wrong!
>>        regex = [NSString stringWithFormat: @"^%@$", regex];
>>        return GSICUStringMatchesRegex(leftResult, regex, compareOptions);
> 
> In case the caller wants to use a "*" as a literal (and not as a "joker" 
> matching any character), the relavant part of the string rightResult would be
> 
> "\*"
> 
> This code converts it into
> 
> "\.*"
> 
> and this will not yield the expected results.
> 
> On MacOS the following "Like" predicate matches:
> 
> leftResult = "**/*" and rightResult = "\*\*\/\*"
> 
> On GNUstep it matches only if the replacements shown above are removed.
> 
> So the stringByReplacingOccurrencesOfString calls must replace only those "*" 
> or "?" in the string that are not escaped. Any objections?


I'm not familiar with NSPredicate, but ues, it sounds like OSX supports 
backslashes for escaping wildcards, in which case:
agreed ... we should parse the string for escapes and replace only unescaped 
values.

Do backslashes need any other special processing?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]