From c8aa75d4b61d3a87133eac69da6e3b48e434a316 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Wed, 22 Mar 2017 16:12:15 -0400 Subject: [PATCH 1/3] Drop section moves if they are also deleted or inserted --- Source/Common/IGListBatchUpdateData.mm | 5 +++-- Tests/IGListBatchUpdateDataTests.m | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/Common/IGListBatchUpdateData.mm b/Source/Common/IGListBatchUpdateData.mm index 6d564cfc7..90bac6227 100644 --- a/Source/Common/IGListBatchUpdateData.mm +++ b/Source/Common/IGListBatchUpdateData.mm @@ -77,9 +77,10 @@ - (instancetype)initWithInsertSections:(NSIndexSet *)insertSections const NSInteger from = move.from; const NSInteger to = move.to; - // if the move is already deleted or inserted, discard it and use delete+insert instead + // if the move is already deleted or inserted, discard it because count-changing operations must match + // with data source changesw if ([deleteSections containsIndex:from] || [insertSections containsIndex:to]) { - convertMoveToDeleteAndInsert(mMoveSections, move, mDeleteSections, mInsertSections); + [mMoveSections removeObject:move]; } else { fromMap[from] = move; toMap[to] = move; diff --git a/Tests/IGListBatchUpdateDataTests.m b/Tests/IGListBatchUpdateDataTests.m index fb457df36..d0768805f 100644 --- a/Tests/IGListBatchUpdateDataTests.m +++ b/Tests/IGListBatchUpdateDataTests.m @@ -119,4 +119,18 @@ - (void)test_whenMovingIndexPaths_withSectionMoved_thatResultConvertsToDeletesAn XCTAssertEqualObjects(result.insertSections, indexSet(@[@1])); } +- (void)test_whenMovingSections_withMoveFromConflictWithDelete_thatResultDropsTheMove { + IGListBatchUpdateData *result = [[IGListBatchUpdateData alloc] initWithInsertSections:indexSet(@[]) + deleteSections:indexSet(@[@2]) + moveSections:[NSSet setWithArray:@[newMove(2, 6), newMove(0, 2)]] + insertIndexPaths:[NSSet new] + deleteIndexPaths:[NSSet new] + moveIndexPaths:[NSSet new]]; + XCTAssertEqual(result.deleteSections.count, 1); + XCTAssertEqual(result.moveSections.count, 1); + XCTAssertEqual(result.insertSections.count, 0); + XCTAssertEqualObjects(result.deleteSections, indexSet(@[@2])); + XCTAssertEqualObjects(result.moveSections.anyObject, newMove(0, 2)); +} + @end From e18ba5a7a66f85d0a987ce8161fe4788a05fc3a2 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Wed, 22 Mar 2017 16:13:44 -0400 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f77422aa3..c8a8c8871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,8 @@ This release closes the [3.0.0 milestone](https://github.com/Instagram/IGListKit - Only collect batch updates when explicitly inside the batch update block, execute them otherwise. Fixes dropped updates. [Ryan Nystrom](https://github.com/rnystrom) [(#494)](https://github.com/Instagram/IGListKit/pull/494) +- Fix a potential crash when a section is moved and deleted at the same time. [Ryan Nystrom](https://github.com/rnystrom) [(#577)](https://github.com/Instagram/IGListKit/pull/577) + 2.1.0 ----- From 989f2d787a1924b53bfb8a81c6302b5ea76c3b94 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Thu, 23 Mar 2017 11:53:30 -0400 Subject: [PATCH 3/3] typo --- Source/Common/IGListBatchUpdateData.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Common/IGListBatchUpdateData.mm b/Source/Common/IGListBatchUpdateData.mm index 90bac6227..ae909fa68 100644 --- a/Source/Common/IGListBatchUpdateData.mm +++ b/Source/Common/IGListBatchUpdateData.mm @@ -78,7 +78,7 @@ - (instancetype)initWithInsertSections:(NSIndexSet *)insertSections const NSInteger to = move.to; // if the move is already deleted or inserted, discard it because count-changing operations must match - // with data source changesw + // with data source changes if ([deleteSections containsIndex:from] || [insertSections containsIndex:to]) { [mMoveSections removeObject:move]; } else {