Skip to content

Commit

Permalink
Added check for NSNull pointer types being assigned by json parsing f…
Browse files Browse the repository at this point in the history
…rameworks, if they work alongside autocoding.
  • Loading branch information
rohitggarg committed Jul 3, 2015
1 parent 7fe31ee commit 718754e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AutoCoding/AutoCoding.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ - (void)setWithCoder:(NSCoder *)aDecoder
}
if (object)
{
if (secureSupported && ![object isKindOfClass:propertyClass])
if (secureSupported && ![object isKindOfClass:propertyClass] && object != [NSNull null])
{
[NSException raise:AutocodingException format:@"Expected '%@' to be a %@, but was actually a %@", key, propertyClass, [object class]];
}
Expand Down
13 changes: 12 additions & 1 deletion Tests/UnitTests/DataTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import "TestObject.h"
#import "AutoCoding.h"


@interface DataTests : XCTestCase

@end
Expand Down Expand Up @@ -48,6 +47,18 @@ - (void)testOutputEqualsInput
XCTAssertNotEqualObjects(output.readonlyDynamicProperty, input.readonlyDynamicProperty);
}

- (void)testNullObjectRetention {
TestObject *input = [[TestObject alloc] init];
[input setValue:[NSNull null] forKey:@"publicString"];
//save object
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:input];

//load object
TestObject *output = [NSKeyedUnarchiver unarchiveObjectWithData:data];
XCTAssertEqualObjects(output.publicString, [NSNull null]);

}

- (void)testSecureCoding
{
//create object
Expand Down

0 comments on commit 718754e

Please sign in to comment.