On 3 Mar 2014, at 16:12, Mathias Bauer <[email protected]> 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? _______________________________________________ Discuss-gnustep mailing list [email protected] https://lists.gnu.org/mailman/listinfo/discuss-gnustep
