Skip to content

Commit

Permalink
Add fix and tests for immutable metadata tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
snmaynard committed Nov 1, 2019
1 parent da9669c commit b56950f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/BugsnagCrashReport.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ - (void)addAttribute:(NSString *)attributeName
toTabWithName:(NSString *)tabName {
NSMutableDictionary *allMetadata = [self.metaData mutableCopy];
NSMutableDictionary *allTabData =
allMetadata[tabName] ?: [NSMutableDictionary new];
[allMetadata[tabName] mutableCopy] ?: [NSMutableDictionary new];
if (value) {
id cleanedValue = BSGSanitizeObject(value);
if (!cleanedValue) {
Expand Down
11 changes: 8 additions & 3 deletions Source/BugsnagSink.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#import "BugsnagSink.h"
#import "Bugsnag.h"
#import "BugsnagLogger.h"
#import "BugsnagCollections.h"
#import "BugsnagNotifier.h"
#import "BugsnagKeys.h"
Expand Down Expand Up @@ -101,9 +102,13 @@ - (void)filterReports:(NSDictionary <NSString *, NSDictionary *> *)reports
continue;
BOOL shouldSend = YES;
for (BugsnagBeforeSendBlock block in configuration.beforeSendBlocks) {
shouldSend = block(report, bugsnagReport);
if (!shouldSend)
break;
@try {
shouldSend = block(report, bugsnagReport);
if (!shouldSend)
break;
} @catch (NSException *exception) {
bsg_log_err(@"Error from beforeSend callback: %@", exception);
}
}
if (shouldSend) {
[bugsnagReports addObject:bugsnagReport];
Expand Down
10 changes: 10 additions & 0 deletions Tests/BugsnagCrashReportTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,14 @@ - (void)testAppVersionOverride {
XCTAssertEqualObjects(@"1.2.3", dictionary[@"app"][@"version"]);
}

- (void)testReportAddAttr {
BugsnagCrashReport *report = [[BugsnagCrashReport alloc] initWithKSReport:@{@"user.metaData": @{@"user": @{@"id": @"user id"}}}];
[report addAttribute:@"foo" withValue:@"bar" toTabWithName:@"user"];
}

- (void)testReportAddMetadata {
BugsnagCrashReport *report = [[BugsnagCrashReport alloc] initWithKSReport:@{@"user.metaData": @{@"user": @{@"id": @"user id"}}}];
[report addMetadata:@{@"foo": @"bar"} toTabWithName:@"user"];
}

@end

0 comments on commit b56950f

Please sign in to comment.