mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-17 22:38:19 +00:00
Return nil if accesing OOB section
Summary: Rare crashers that take `NSNotFound` from `sectionFor...` API and then immediately look up the object w/out checking for not found. Instead return nil. Reviewed By: dshahidehpour Differential Revision: D4142946 fbshipit-source-id: ca80f87729b5ee6699740de897d73b819d27d132
This commit is contained in:
parent
386ae07864
commit
1a92c15b50
2 changed files with 14 additions and 1 deletions
|
|
@ -75,7 +75,12 @@
|
|||
}
|
||||
|
||||
- (id)objectForSection:(NSUInteger)section {
|
||||
return self.objects[section];
|
||||
NSArray *objects = self.objects;
|
||||
if (section < objects.count) {
|
||||
return objects[section];
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSUInteger)sectionForObject:(id)object {
|
||||
|
|
|
|||
|
|
@ -82,4 +82,12 @@
|
|||
XCTAssertEqual(counter, 2);
|
||||
}
|
||||
|
||||
- (void)test_whenAccessingOOBSection_thatNilIsReturned {
|
||||
NSArray *objects = @[@0, @1, @2];
|
||||
NSArray *sectionControllers = @[@"a", @"b", @"c"];
|
||||
IGListSectionMap *map = [[IGListSectionMap alloc] initWithMapTable:[NSMapTable strongToStrongObjectsMapTable]];
|
||||
[map updateWithObjects:objects sectionControllers:sectionControllers];
|
||||
XCTAssertNil([map objectForSection:4]);
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Reference in a new issue