discuss-gnustep
[Top][All Lists]
Advanced

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

Bug in NSPredicate?


From: Mathias Bauer
Subject: Bug in NSPredicate?
Date: Mon, 03 Mar 2014 17:12:36 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

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?

Regards,
Mathias



reply via email to

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