Skip to content

Commit

Permalink
fix: Make metadata tabs always mutable (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
snmaynard authored and kattrali committed Nov 4, 2019
1 parent da9669c commit 63f656c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Bug fixes

* Fix unrecognized selector crash when adding metadata
[#430](https://github.com/bugsnag/bugsnag-cocoa/pull/430)

## 5.22.9 (2019-10-16)

### Bug fixes
Expand Down
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 63f656c

Please sign in to comment.