cappuccino / cappuccino

Web Application Framework in JavaScript and Objective-J
https://cappuccino.dev/
GNU Lesser General Public License v2.1
2.2k stars 333 forks source link

"LIKE" Predicate Operator Incorrectly Implemented #2955

Closed aksuska closed 1 year ago

aksuska commented 3 years ago

According to lines 320-322 of CPComparisonPredicate, when the "like" operator is used, the framework uses RegExp.test() for comparison. However, because the expression is unanchored, the behavior is as if the "CONTAINS" operator was used but with wildcard support, and this is not how Cocoa works. The easiest solution is to anchor the expression, i.e. prepend a "^" and append a "$". Note also that the flags ate incorrect--"g" should never be used for tis kind of operator. The corrected code could look like:

 var commut = (_options & CPCaseInsensitivePredicateOption) ? "i":"",
       reg = new RegExp("^"+rhs.escapeForRegExp()+"$",commut);
 return reg.test(lhs);

This is my workaround and works properly.

cappbot commented 3 years ago

Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue.

mrcarlberg commented 3 years ago

Good catch, please make a pull request with these changes along with some new unit test cases. We want this to behave the Cocoa way.

daboe01 commented 3 years ago

-#new +Foundation +#needs-patch +#accepted

cappbot commented 3 years ago

Milestone: Someday. Labels: #accepted, #needs-patch, Foundation. What's next? This issue needs a volunteer to write and submit code to address it.