Skip to content

Commit

Permalink
Follow-up to PR #362: return from callback after invoking completionH…
Browse files Browse the repository at this point in the history
…andler

Follow-up to PR #362: Missing a return statement in several places, which resulted in both the correct and incorrect completionHandlers being called. This could lead to crashes if the callback result is empty or represents an unexpected type.
  • Loading branch information
Eric Vargas committed May 11, 2020
1 parent 6af4c8f commit f278335
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Classes/YTPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ - (void)playbackRate:(_Nullable YTFloatCompletionHandler)completionHandler {
}
if (!result || ![result isKindOfClass:[NSNumber class]]) {
completionHandler(0, nil);
return;
}
completionHandler([result floatValue], nil);
}];
Expand All @@ -271,6 +272,7 @@ - (void)availablePlaybackRates:(_Nullable YTArrayCompletionHandler)completionHan
}
if (!result || ![result isKindOfClass:[NSArray class]]) {
completionHandler(nil, nil);
return;
}
completionHandler(result, nil);
}];
Expand Down Expand Up @@ -361,6 +363,7 @@ - (void)duration:(_Nullable YTDoubleCompletionHandler)completionHandler {
}
if (!result || ![result isKindOfClass:[NSNumber class]]) {
completionHandler(0, nil);
return;
}
completionHandler([result doubleValue], nil);
}];
Expand All @@ -378,6 +381,7 @@ - (void)videoUrl:(_Nullable YTURLCompletionHandler)completionHandler {
}
if (!result || ![result isKindOfClass:[NSString class]]) {
completionHandler(nil, nil);
return;
}
completionHandler([NSURL URLWithString:result], nil);
}];
Expand All @@ -395,6 +399,7 @@ - (void)videoEmbedCode:(_Nullable YTStringCompletionHandler)completionHandler {
}
if (!result || ![result isKindOfClass:[NSString class]]) {
completionHandler(nil, nil);
return;
}
completionHandler(result, nil);
}];
Expand All @@ -413,6 +418,7 @@ - (void)playlist:(_Nullable YTArrayCompletionHandler)completionHandler {
}
if (!result || ![result isKindOfClass:[NSArray class]]) {
completionHandler(nil, nil);
return;
}
completionHandler(result, nil);
}];
Expand All @@ -430,6 +436,7 @@ - (void)playlistIndex:(_Nullable YTIntCompletionHandler)completionHandler {
}
if (!result || ![result isKindOfClass:[NSNumber class]]) {
completionHandler(0, nil);
return;
}
completionHandler([result intValue], nil);
}];
Expand Down

1 comment on commit f278335

@quynv186
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WKWebView is not exists Cocoapod?

Please sign in to comment.