From a42af79040d6506eb431a04b8cf9d45f0f8c0ffa Mon Sep 17 00:00:00 2001 From: Ryan Olson Date: Sat, 23 May 2015 14:59:28 -0700 Subject: [PATCH] Protect against a nil NSURLConnection or NSURLSession object being passed to the swizzled delegate methods. See https://github.com/Flipboard/FLEX/issues/61 for motivation and background. --- Classes/Network/PonyDebugger/FLEXNetworkObserver.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Classes/Network/PonyDebugger/FLEXNetworkObserver.m b/Classes/Network/PonyDebugger/FLEXNetworkObserver.m index 6f2950b12d..631dd26803 100644 --- a/Classes/Network/PonyDebugger/FLEXNetworkObserver.m +++ b/Classes/Network/PonyDebugger/FLEXNetworkObserver.m @@ -149,6 +149,14 @@ + (SEL)swizzledSelectorForSelector:(SEL)selector /// The superclass implementation (and implementations in classes above that) will be executed without inteference if called from the original implementation. + (void)sniffWithoutDuplicationForObject:(NSObject *)object selector:(SEL)selector sniffingBlock:(void (^)(void))sniffingBlock originalImplementationBlock:(void (^)(void))originalImplementationBlock { + // If we don't have an object to detect nested calls on, just run the original implmentation and bail. + // This case can happen if someone besides the URL loading system calls the delegate methods directly. + // See https://github.com/Flipboard/FLEX/issues/61 for an example. + if (!object) { + originalImplementationBlock(); + return; + } + const void *key = selector; // Don't run the sniffing block if we're inside a nested call