Skip to content

Commit

Permalink
Safely inspect bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Jan 3, 2017
1 parent 7a820b7 commit 4cd853c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Parse/Internal/Object/Subclassing/PFObjectSubclassingController.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,12 @@ - (void)scanForUnregisteredSubclasses:(BOOL)shouldSubscribe {
queue:nil
usingBlock:^(NSNotification *note) {
@strongify(self);
[self _registerSubclassesInBundle:note.object];
[self _registerSubclassesInLoadedBundle:note.object];
}];
}
NSArray *bundles = [[NSBundle allFrameworks] arrayByAddingObjectsFromArray:[NSBundle allBundles]];
for (NSBundle *bundle in bundles) {
// Skip bundles that aren't loaded yet.
if (!bundle.loaded || !bundle.executablePath) {
continue;
}
// Filter out any system bundles
if ([bundle.bundlePath hasPrefix:@"/System/"] || [bundle.bundlePath hasPrefix:@"/Library/"]) {
continue;
}
[self _registerSubclassesInBundle:bundle];
[self _registerSubclassesInLoadedBundle:bundle];
}
}

Expand Down Expand Up @@ -338,6 +330,18 @@ - (void)_rawRegisterSubclass:(Class)kls {
_registeredSubclasses[[kls parseClassName]] = subclassInfo;
}

- (void)_registerSubclassesInLoadedBundle:(NSBundle *)bundle {
// Skip bundles that aren't loaded yet.
if (!bundle.loaded || !bundle.executablePath) {
return;
}
// Filter out any system bundles
if ([bundle.bundlePath hasPrefix:@"/System/"] || [bundle.bundlePath hasPrefix:@"/Library/"] || [bundle.bundlePath rangeOfString:@"iPhoneSimulator.sdk"].location != NSNotFound) {
return;
}
[self _registerSubclassesInBundle:bundle];
}

- (void)_registerSubclassesInBundle:(NSBundle *)bundle {
PFConsistencyAssert(bundle.loaded, @"Cannot register subclasses in a bundle that hasn't been loaded!");

Expand Down

0 comments on commit 4cd853c

Please sign in to comment.