Skip to content

Commit

Permalink
fix: setting SDK name through options[sdk][name] shouldn't clear vers…
Browse files Browse the repository at this point in the history
…ion (#2139)

* fix: setting SDK name through options[sdk][name] shouldn't clear version

* chore: update changelog
  • Loading branch information
vaind authored Sep 9, 2022
1 parent 193647c commit 7cd89d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Can't find app image when swizzling (#2124)
- Crash with screenshot is reported twice (#2134)
- Setting SDK name through `options[sdk][name]` shouldn't clear version (#2139)

## 7.24.1

Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ - (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
// Note: we should remove this code once the hybrid SDKs move over to the new
// PrivateSentrySDKOnly setter functions.
if ([options[@"sdk"] isKindOfClass:[NSDictionary class]]) {
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithDict:options];
SentrySdkInfo *defaults = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithDict:options orDefaults:defaults];
SentryMeta.versionString = sdkInfo.version;
SentryMeta.sdkName = sdkInfo.name;
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/SentryTests/PrivateSentrySDKOnlyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
func testSetSdkName() {
let originalName = PrivateSentrySDKOnly.getSdkName()
let name = "Some SDK name"
let originalVersion = SentryMeta.versionString
XCTAssertNotEqual(originalVersion, "")

PrivateSentrySDKOnly.setSdkName(name)
XCTAssertEqual(SentryMeta.sdkName, name)
XCTAssertEqual(SentryMeta.versionString, originalVersion)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkName(), name)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkVersionString(), originalVersion)

PrivateSentrySDKOnly.setSdkName(originalName)
XCTAssertEqual(SentryMeta.sdkName, originalName)
XCTAssertEqual(SentryMeta.versionString, originalVersion)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkName(), originalName)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkVersionString(), originalVersion)
}

func testSetSdkNameAndVersion() {
Expand Down
10 changes: 8 additions & 2 deletions Tests/SentryTests/SentryOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ - (void)testSetCustomSdkInfo
- (void)testSetCustomSdkName
{
NSDictionary *dict = @{ @"name" : @"custom.sdk" };
NSString *originalVersion = SentryMeta.versionString;

NSError *error = nil;
SentryOptions *options =
Expand All @@ -614,13 +615,16 @@ - (void)testSetCustomSdkName
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(dict[@"name"], options.sdkInfo.name);
XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version); // default version
// version stays unchanged
XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version);
XCTAssertEqual(SentryMeta.versionString, originalVersion);
#pragma clang diagnostic pop
}

- (void)testSetCustomSdkVersion
{
NSDictionary *dict = @{ @"version" : @"1.2.3-alpha.0" };
NSString *originalName = SentryMeta.sdkName;

NSError *error = nil;
SentryOptions *options =
Expand All @@ -631,8 +635,10 @@ - (void)testSetCustomSdkVersion

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name); // default name
XCTAssertEqual(dict[@"version"], options.sdkInfo.version);
// name stays unchanged
XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name);
XCTAssertEqual(SentryMeta.sdkName, originalName);
#pragma clang diagnostic pop

NSDictionary *info = [[NSBundle bundleForClass:[SentryClient class]] infoDictionary];
Expand Down

0 comments on commit 7cd89d4

Please sign in to comment.