Skip to content

Commit

Permalink
Merge pull request #1090 from AmpMe/fix-1006
Browse files Browse the repository at this point in the history
Safely inspect bundles for classes
  • Loading branch information
hramos authored Feb 7, 2017
2 parents 7a820b7 + 4cd853c commit f6f4d32
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 f6f4d32

Please sign in to comment.