-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix for LIB-1416 & Github #846 - Stops blindly passing dictionaries. - Property dictionaries are checked for NSCoding conformance to ensure they can be serialized. - Property dictionaries are deep copied so contents can’t change while the pipeline is in progress. - Puts a try/catch arrangement as a temporary guard against crashes for serialization failures until the storage format can be changed. * Fixed missing ; * Added test for deepCopy/conformance additions.
- Loading branch information
Showing
7 changed files
with
182 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// PropSerializationTests.m | ||
// AnalyticsTests | ||
// | ||
// Created by Brandon Sneed on 11/20/19. | ||
// Copyright © 2019 Segment. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
@import Analytics; | ||
|
||
@protocol SEGSerializableDeepCopy <NSObject> | ||
-(id _Nullable) serializableDeepCopy; | ||
@end | ||
|
||
@interface NSDictionary(SerializableDeepCopy) <SEGSerializableDeepCopy> | ||
@end | ||
|
||
@interface NSArray(SerializableDeepCopy) <SEGSerializableDeepCopy> | ||
@end | ||
|
||
@interface SerializationTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation SerializationTests | ||
|
||
- (void)setUp { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
- (void)tearDown { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
- (void)testDeepCopyAndConformance { | ||
NSDictionary *nonserializable = @{@"test": @1, @"nonserializable": self, @"nested": @{@"nonserializable": self}, @"array": @[@1, @2, @3, self]}; | ||
NSDictionary *serializable = @{@"test": @1, @"nonserializable": @0, @"nested": @{@"nonserializable": @0}, @"array": @[@1, @2, @3, @0]}; | ||
|
||
NSDictionary *aCopy = [serializable serializableDeepCopy]; | ||
XCTAssert(aCopy != serializable); | ||
|
||
NSDictionary *sub = [serializable objectForKey:@"nested"]; | ||
NSDictionary *subCopy = [aCopy objectForKey:@"nested"]; | ||
XCTAssert(sub != subCopy); | ||
|
||
NSDictionary *array = [serializable objectForKey:@"array"]; | ||
NSDictionary *arrayCopy = [aCopy objectForKey:@"array"]; | ||
XCTAssert(array != arrayCopy); | ||
|
||
XCTAssertNoThrow([serializable serializableDeepCopy]); | ||
XCTAssertThrows([nonserializable serializableDeepCopy]); | ||
} | ||
|
||
@end |