Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nil content value #289

Merged
merged 4 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## 5.X.X (TBD)

### Bug Fixes

* Handle potential nil content value in RegisterErrorData class [#289](https://github.com/bugsnag/bugsnag-cocoa/pull/289)

## 5.15.6 (30 May 2018)

### Bug Fixes
Expand Down
6 changes: 5 additions & 1 deletion Source/BugsnagCrashReport.m
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,13 @@ + (instancetype)errorDataFromThreads:(NSArray *)threads {
}
NSString *contentValue = data[@"value"];

if (!contentValue) {
continue;
}

if ([self isReservedWord:contentValue]) {
reservedWord = contentValue;
} else if (!([[contentValue componentsSeparatedByString:@"/"] count] > 2)) {
} else if ([[contentValue componentsSeparatedByString:@"/"] count] <= 2) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change just simplifies the condition to make it more readable

// must be a string that isn't a reserved word and isn't a filepath
[interestingValues addObject:contentValue];
}
Expand Down
4 changes: 4 additions & 0 deletions iOS/Bugsnag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
F4295C14DCDDF541188CDE66 /* BugsnagSessionFileStore.h in Headers */ = {isa = PBXBuildFile; fileRef = F42955025DBE1DCEFD928CAA /* BugsnagSessionFileStore.h */; };
F4295C52A30DC98515F2FF02 /* BugsnagSessionTrackingApiClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F4295FBD23F478FC6216A006 /* BugsnagSessionTrackingApiClient.m */; };
F4295DB3B395327B82A47A78 /* BugsnagSessionFileStore.m in Sources */ = {isa = PBXBuildFile; fileRef = F42954ACC6FFDDE3C8471495 /* BugsnagSessionFileStore.m */; };
F4295F017754324FD52CCE46 /* RegisterErrorDataTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F42954B7D892334E7551F0F3 /* RegisterErrorDataTest.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -589,6 +590,7 @@
F429517A5571A61A897E963D /* BugsnagSessionTrackingApiClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BugsnagSessionTrackingApiClient.h; path = ../Source/BugsnagSessionTrackingApiClient.h; sourceTree = SOURCE_ROOT; };
F42953E7E61199381E0405CC /* BugsnagFileStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BugsnagFileStore.h; path = ../Source/BugsnagFileStore.h; sourceTree = SOURCE_ROOT; };
F42954ACC6FFDDE3C8471495 /* BugsnagSessionFileStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BugsnagSessionFileStore.m; path = ../Source/BugsnagSessionFileStore.m; sourceTree = SOURCE_ROOT; };
F42954B7D892334E7551F0F3 /* RegisterErrorDataTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegisterErrorDataTest.m; sourceTree = "<group>"; };
F42955025DBE1DCEFD928CAA /* BugsnagSessionFileStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BugsnagSessionFileStore.h; path = ../Source/BugsnagSessionFileStore.h; sourceTree = SOURCE_ROOT; };
F429554A50F3ABE60537F70E /* BugsnagKSCrashSysInfoParserTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugsnagKSCrashSysInfoParserTest.m; sourceTree = "<group>"; };
F42958B2E67C338E3086EAC2 /* BugsnagFileStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BugsnagFileStore.m; path = ../Source/BugsnagFileStore.m; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -726,6 +728,7 @@
8A2C8F951C6BC08600846019 /* report.json */,
8A2C8F291C6BBD2300846019 /* TestsInfo.plist */,
F429554A50F3ABE60537F70E /* BugsnagKSCrashSysInfoParserTest.m */,
F42954B7D892334E7551F0F3 /* RegisterErrorDataTest.m */,
);
name = Tests;
path = BugsnagTests;
Expand Down Expand Up @@ -1237,6 +1240,7 @@
E78C1EF31FCC615400B976D3 /* BugsnagSessionTrackingPayloadTest.m in Sources */,
E78C1EF11FCC2F1700B976D3 /* BugsnagSessionTrackerTest.m in Sources */,
F4295995C3259BF7D9730BC4 /* BugsnagKSCrashSysInfoParserTest.m in Sources */,
F4295F017754324FD52CCE46 /* RegisterErrorDataTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
248 changes: 248 additions & 0 deletions iOS/BugsnagTests/RegisterErrorDataTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
//
// Created by Jamie Lynch on 11/06/2018.
// Copyright (c) 2018 Bugsnag. All rights reserved.
//


#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>

@interface RegisterErrorData
+ (instancetype)errorDataFromThreads:(NSArray *)threads;
@property (nonatomic, strong) NSString *errorClass;
@property (nonatomic, strong) NSString *errorMessage;
@end

@interface RegisterErrorDataTest : XCTestCase
@end

@implementation RegisterErrorDataTest


- (void)testNilAddresses {
XCTAssertNil([RegisterErrorData errorDataFromThreads:nil]);
}

- (void)testEmptyAddresses {
XCTAssertNil([RegisterErrorData errorDataFromThreads:@[]]);
}

- (void)testEmptyCrashedThreadDict {
NSDictionary *thread = @{
@"crashed": @YES
};
XCTAssertNil([RegisterErrorData errorDataFromThreads:@[thread]]);
}

- (void)testEmptyNotableAddresses {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertNil(data);
}

- (void)testEmptyContentValue {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertNil(data);
}

- (void)testHasType {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertNil(data);
}

- (void)testHasTypeAndValue{
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"Hello, World!"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertNil(data);
}

- (void)testFatalError {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"fatal error"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertNotNil(data);
XCTAssertEqualObjects(@"fatal error", data.errorClass);
XCTAssertEqualObjects(@"", data.errorMessage);
}

- (void)testAssertionFailed {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"assertion failed"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertNotNil(data);
XCTAssertEqualObjects(@"assertion failed", data.errorClass);
XCTAssertEqualObjects(@"", data.errorMessage);
}

- (void)testPreconditionFailed {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"precondition failed"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertNotNil(data);
XCTAssertEqualObjects(@"precondition failed", data.errorClass);
XCTAssertEqualObjects(@"", data.errorMessage);
}

- (void)testSingleMessageValue {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"fatal error"
},
@"message": @{
@"type": @"string",
@"value": @"Single Message"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertEqualObjects(@"Single Message", data.errorMessage);
}

- (void)testMultiMessageValue {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"fatal error"
},
@"message": @{
@"type": @"string",
@"value": @"A is for aardvark"
},
@"message2": @{
@"type": @"string",
@"value": @"Z is for zebra"
},
@"message3": @{
@"type": @"string",
@"value": @"C is for crayfish"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertEqualObjects(@"A is for aardvark | C is for crayfish | Z is for zebra", data.errorMessage);
}

- (void)testStackExcluded {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"fatal error"
},
@"message": @{
@"type": @"stack",
@"value": @"0xf0924501"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertEqualObjects(@"", data.errorMessage);
}

- (void)testOtherTypesExcluded {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"fatal error"
},
@"message": @{
@"type": @"someOtherType",
@"value": @"do not serialise"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertEqualObjects(@"", data.errorMessage);
}

- (void)testFilepathExcluded {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"fatal error"
},
@"message": @{
@"type": @"string",
@"value": @"/usr/share/locale"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertEqualObjects(@"", data.errorMessage);
}

- (void)testForwardSlashIncluded {
NSDictionary *thread = @{
@"crashed": @YES,
@"notable_addresses": @{
@"hello_world": @{
@"type": @"string",
@"value": @"fatal error"
},
@"message": @{
@"type": @"string",
@"value": @"usr/share"
}
}
};
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:@[thread]];
XCTAssertEqualObjects(@"usr/share", data.errorMessage);
}

@end