NSPredicate Value Fix

* Check if object is an NSExpression object

* Fix Indentation

* Update Changelog

* Add test case
This commit is contained in:
Hugo Melder 2022-08-24 18:01:30 +02:00 committed by GitHub
parent 68f6862ff2
commit 7fd20d1ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View file

@ -1,3 +1,11 @@
2022-08-16 Hugo Melder <contact@hugomelder.com>
* Source/NSPredicate.m:
When parsing an NSArray in -expressionValueWithObject:context:,
check if the array entry is a NSExpression object.
* Tests/base/NSPredicate/basic.m:
Test filter operation.
2022-08-16 Hugo Melder <contact@hugomelder.com>
* Source/win32/GSFileHandle.m:

View file

@ -1374,8 +1374,18 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
while (index < count)
{
NSExpression *e = [(NSArray*)_obj objectAtIndex: index++];
id o = [e expressionValueWithObject: e context: context];
id e = [(NSArray*)_obj objectAtIndex: index++];
id o;
/* Array index is not always a NSExpression object
* (e.g. When specified as an argument instead of
* an inline expression).
*/
if ([e isKindOfClass: [NSExpression class]]) {
o = [e expressionValueWithObject: e context: context];
} else {
o = e;
}
[tmp addObject: o];
}

View file

@ -250,6 +250,11 @@ int main()
p = [NSPredicate predicateWithFormat: @"sum(a) == 3"];
PASS([p evaluateWithObject: a], "aggregate sum works");
p = [NSPredicate predicateWithFormat: @"self IN %@", @[@"yes"]];
a = [@[@"yes", @"no"] filteredArrayUsingPredicate: p];
PASS_EQUAL([a description], @"(yes)",
"predicate created with format can filter an array")
END_SET("basic")
return 0;