Skip to content

Commit

Permalink
Merge pull request #84 from calabash/bugfix/crash-when-predicate-type…
Browse files Browse the repository at this point in the history
…-mismatch

Fix deserialization of boolean in filters
  • Loading branch information
krukow committed Oct 22, 2014
2 parents 04f1421 + 9432d35 commit c1abb7a
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions calabash/Classes/UISpec/UIScriptASTWith.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,57 @@ - (NSMutableArray *) evalWith:(NSArray *) views direction:(UIScriptASTDirectionT

if (self.selectorName) {
if ([v respondsToSelector:_selector]) {
void *val = [v performSelector:_selector];
BOOL Bvalue;
NSMethodSignature *sig = [v methodSignatureForSelector:_selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
const char *type = [[invocation methodSignature] methodReturnType];
NSString *returnType = [NSString stringWithFormat:@"%s", type];
const char *trimmedType = [[returnType substringToIndex:1]
cStringUsingEncoding:NSASCIIStringEncoding];
BOOL boolReturnType = ('B' == *trimmedType);
BOOL objectReturnType = ('*' == *trimmedType);

void *val = nil;
if (boolReturnType) {
[invocation setSelector:_selector];
[invocation setTarget:v];
@try {
[invocation invoke];
}
@catch (NSException *exception) {
NSLog(@"Perform %@ with target %@ caught %@: %@", _selectorName,v, [exception name], [exception reason]);
break;
}
[invocation getReturnValue:(void **) &Bvalue];
}
else {
val = [v performSelector:_selector];
}
switch (self.valueType) {
case UIScriptLiteralTypeInteger:
if ((NSInteger) val == self.integerValue) {
case UIScriptLiteralTypeInteger: {
if (boolReturnType) {
if ((self.integerValue == 1 && Bvalue) || (self.integerValue == 0 && !Bvalue)) {
[res addObject:v];
}
}
else if ((NSInteger) val == self.integerValue) {
[res addObject:v];
}
break;
}
case UIScriptLiteralTypeString: {
if (val != nil && ([(NSString *) val isEqualToString:(NSString *) self.objectValue])) {
[res addObject:v];
if (objectReturnType) {
id valObj = (id) val;
if (valObj != nil
&& [valObj respondsToSelector:@selector(isEqualToString:)]
&& ([valObj isEqualToString:(NSString *) self.objectValue])) {
[res addObject:v];
}
}
break;
}
case UIScriptLiteralTypeBool:
if (self.boolValue == (BOOL) val) {
if (boolReturnType && self.boolValue == Bvalue) {
[res addObject:v];
}
break;
Expand Down

0 comments on commit c1abb7a

Please sign in to comment.