Skip to content

Commit

Permalink
Fix crash if data was not serializable by NSJSONSerialization (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarywojcik authored and plivesey committed Oct 5, 2016
1 parent 38dbc8d commit 214b9f5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions LayoutTest/TestCase/LYTLayoutFailingTestSnapshotRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ - (void)appendViewWithWidth:(CGFloat)width
NSString *imagePath = [NSString stringWithFormat:@"%@/%@", [self methodNameForInvocation:invocation], [self nameForImageWithWidth:width height:height data:data]];
NSString *dataDescription = nil;
if (data) {
NSData *serializedJSON = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
if (serializedJSON) {
dataDescription = [[NSString alloc] initWithData:serializedJSON encoding:NSUTF8StringEncoding];
if ([NSJSONSerialization isValidJSONObject:data]) {
NSData *serializedJSON = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
if (serializedJSON) {
dataDescription = [[NSString alloc] initWithData:serializedJSON encoding:NSUTF8StringEncoding];
}
} else {
dataDescription = [data description];
}
}
NSString *errorHTML = [NSString stringWithFormat:@"<TR><TD>%@</TD><TD><IMG src='%@' alt='No Image'></TD><TD>%@</TD></TR>", [description lyt_stringByAddingXMLEscaping], imagePath, dataDescription];
Expand Down

0 comments on commit 214b9f5

Please sign in to comment.