Skip to content

Commit 0b30a6d

Browse files
ref: Make sentry_fromIso8601String nullable (#4982)
sentry_fromIso8601String can return nil, if passing in a garbage string. Now the method signature correctly reflects this.
1 parent bf07cbb commit 0b30a6d

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
62872B5F2BA1B7F300A4FA7D /* NSLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62872B5E2BA1B7F300A4FA7D /* NSLock.swift */; };
120120
62872B632BA1B86100A4FA7D /* NSLockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62872B622BA1B86100A4FA7D /* NSLockTests.swift */; };
121121
62885DA729E946B100554F38 /* TestConncurrentModifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62885DA629E946B100554F38 /* TestConncurrentModifications.swift */; };
122+
628B89022D841D7F004B6F2A /* SentryDateUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628B89012D841D7F004B6F2A /* SentryDateUtilsTests.swift */; };
122123
629194A92D51F976000F7C6B /* SentryDebugMetaCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629194A82D51F976000F7C6B /* SentryDebugMetaCodable.swift */; };
123124
6293F5752D422A95002BC3BD /* SentryStacktraceCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6293F5742D422A8A002BC3BD /* SentryStacktraceCodable.swift */; };
124125
629428802CB3BF69002C454C /* SwizzleClassNameExclude.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6294287F2CB3BF4E002C454C /* SwizzleClassNameExclude.swift */; };
@@ -831,14 +832,14 @@
831832
D4C5F59A2D4249E6002A9BF6 /* DataSentryTracingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C5F5992D4249E0002A9BF6 /* DataSentryTracingIntegrationTests.swift */; };
832833
D4E3F35D2D4A864600F79E2B /* SentryNSDictionarySanitizeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D42E48582D48FC8F00D251BC /* SentryNSDictionarySanitizeTests.swift */; };
833834
D4E3F35E2D4A877300F79E2B /* SentryNSDictionarySanitize+Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = D41909942D490006002B83D0 /* SentryNSDictionarySanitize+Tests.m */; };
834-
D4EDF9842D0B2A210071E7B3 /* Data+SentryTracing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */; };
835835
D4E829D22D75E2EC00D375AD /* SentryDefaultViewRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E829D12D75E2DE00D375AD /* SentryDefaultViewRenderer.swift */; };
836836
D4E829D42D75E34A00D375AD /* SentryExperimentalViewRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E829D32D75E34A00D375AD /* SentryExperimentalViewRenderer.swift */; };
837837
D4E829D62D75E39B00D375AD /* SentryViewRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E829D52D75E39900D375AD /* SentryViewRenderer.swift */; };
838838
D4E829D82D75E57900D375AD /* SentryMaskRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E829D72D75E56C00D375AD /* SentryMaskRenderer.swift */; };
839839
D4E829DA2D75F70300D375AD /* SentryDefaultMaskRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E829D92D75F70100D375AD /* SentryDefaultMaskRenderer.swift */; };
840840
D4E829DC2D75F71200D375AD /* SentryExperimentalMaskRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E829DB2D75F71200D375AD /* SentryExperimentalMaskRenderer.swift */; };
841841
D4E829DF2D75FCF000D375AD /* SentryGraphicsImageRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E829DE2D75FCE800D375AD /* SentryGraphicsImageRenderer.swift */; };
842+
D4EDF9842D0B2A210071E7B3 /* Data+SentryTracing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */; };
842843
D4F2B5352D0C69D500649E42 /* SentryCrashCTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F2B5342D0C69D100649E42 /* SentryCrashCTests.swift */; };
843844
D8019910286B089000C277F0 /* SentryCrashReportSinkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D801990F286B089000C277F0 /* SentryCrashReportSinkTests.swift */; };
844845
D802994E2BA836EF000F0081 /* SentryOnDemandReplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = D802994D2BA836EF000F0081 /* SentryOnDemandReplay.swift */; };
@@ -1195,6 +1196,7 @@
11951196
62872B5E2BA1B7F300A4FA7D /* NSLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSLock.swift; sourceTree = "<group>"; };
11961197
62872B622BA1B86100A4FA7D /* NSLockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSLockTests.swift; sourceTree = "<group>"; };
11971198
62885DA629E946B100554F38 /* TestConncurrentModifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestConncurrentModifications.swift; sourceTree = "<group>"; };
1199+
628B89012D841D7F004B6F2A /* SentryDateUtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDateUtilsTests.swift; sourceTree = "<group>"; };
11981200
629194A82D51F976000F7C6B /* SentryDebugMetaCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDebugMetaCodable.swift; sourceTree = "<group>"; };
11991201
6293F5742D422A8A002BC3BD /* SentryStacktraceCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryStacktraceCodable.swift; sourceTree = "<group>"; };
12001202
6294287F2CB3BF4E002C454C /* SwizzleClassNameExclude.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwizzleClassNameExclude.swift; sourceTree = "<group>"; };
@@ -2001,14 +2003,14 @@
20012003
D4AF00222D2E931000F5F3D7 /* SentryNSFileManagerSwizzling.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryNSFileManagerSwizzling.h; path = include/SentryNSFileManagerSwizzling.h; sourceTree = "<group>"; };
20022004
D4AF00242D2E93C400F5F3D7 /* SentryNSFileManagerSwizzlingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryNSFileManagerSwizzlingTests.m; sourceTree = "<group>"; };
20032005
D4C5F5992D4249E0002A9BF6 /* DataSentryTracingIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSentryTracingIntegrationTests.swift; sourceTree = "<group>"; };
2004-
D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+SentryTracing.swift"; sourceTree = "<group>"; };
20052006
D4E829D12D75E2DE00D375AD /* SentryDefaultViewRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDefaultViewRenderer.swift; sourceTree = "<group>"; };
20062007
D4E829D32D75E34A00D375AD /* SentryExperimentalViewRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExperimentalViewRenderer.swift; sourceTree = "<group>"; };
20072008
D4E829D52D75E39900D375AD /* SentryViewRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryViewRenderer.swift; sourceTree = "<group>"; };
20082009
D4E829D72D75E56C00D375AD /* SentryMaskRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMaskRenderer.swift; sourceTree = "<group>"; };
20092010
D4E829D92D75F70100D375AD /* SentryDefaultMaskRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDefaultMaskRenderer.swift; sourceTree = "<group>"; };
20102011
D4E829DB2D75F71200D375AD /* SentryExperimentalMaskRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExperimentalMaskRenderer.swift; sourceTree = "<group>"; };
20112012
D4E829DE2D75FCE800D375AD /* SentryGraphicsImageRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryGraphicsImageRenderer.swift; sourceTree = "<group>"; };
2013+
D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+SentryTracing.swift"; sourceTree = "<group>"; };
20122014
D4F2B5342D0C69D100649E42 /* SentryCrashCTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashCTests.swift; sourceTree = "<group>"; };
20132015
D800942628F82F3A005D3943 /* SwiftDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDescriptor.swift; sourceTree = "<group>"; };
20142016
D801990F286B089000C277F0 /* SentryCrashReportSinkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashReportSinkTests.swift; sourceTree = "<group>"; };
@@ -3298,6 +3300,7 @@
32983300
33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */,
32993301
62375FB82B47F9F000CC55F1 /* SentryDependencyContainerTests.swift */,
33003302
62CFD9A82C99741100834E1B /* SentryInvalidJSONStringTests.swift */,
3303+
628B89012D841D7F004B6F2A /* SentryDateUtilsTests.swift */,
33013304
);
33023305
path = Helper;
33033306
sourceTree = "<group>";
@@ -3839,15 +3842,6 @@
38393842
name = Transaction;
38403843
sourceTree = "<group>";
38413844
};
3842-
D468C0602D36699700964230 /* IO */ = {
3843-
isa = PBXGroup;
3844-
children = (
3845-
D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */,
3846-
D468C0612D3669A200964230 /* SentryFileIOTracker+SwiftHelpers.swift */,
3847-
);
3848-
path = IO;
3849-
sourceTree = "<group>";
3850-
};
38513845
D4009EA02D77196F0007AF30 /* ViewCapture */ = {
38523846
isa = PBXGroup;
38533847
children = (
@@ -3857,6 +3851,15 @@
38573851
path = ViewCapture;
38583852
sourceTree = "<group>";
38593853
};
3854+
D468C0602D36699700964230 /* IO */ = {
3855+
isa = PBXGroup;
3856+
children = (
3857+
D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */,
3858+
D468C0612D3669A200964230 /* SentryFileIOTracker+SwiftHelpers.swift */,
3859+
);
3860+
path = IO;
3861+
sourceTree = "<group>";
3862+
};
38603863
D46D45E22D5F3FD600A1CB35 /* Plans */ = {
38613864
isa = PBXGroup;
38623865
children = (
@@ -5410,6 +5413,7 @@
54105413
D8CE69BC277E39C700C6EC5C /* SentryFileIOTrackingIntegrationObjCTests.m in Sources */,
54115414
D85D3BEA278DF63D001B2889 /* SentryByteCountFormatterTests.swift in Sources */,
54125415
7BBD18A2244EE2FD00427C76 /* TestResponseFactory.swift in Sources */,
5416+
628B89022D841D7F004B6F2A /* SentryDateUtilsTests.swift in Sources */,
54135417
D808FB8B281BCE96009A2A33 /* TestSentrySwizzleWrapper.swift in Sources */,
54145418
630C01941EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m in Sources */,
54155419
7B59398424AB481B0003AAD2 /* NotificationCenterTestCase.swift in Sources */,

Sources/Sentry/SentryDateUtils.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
return isoFormatter;
4343
}
4444

45-
NSDate *
46-
sentry_fromIso8601String(NSString *string)
45+
NSDate *_Nullable sentry_fromIso8601String(NSString *string)
4746
{
4847
NSDate *date = [sentryGetIso8601FormatterWithMillisecondPrecision() dateFromString:string];
4948
if (nil == date) {

Sources/Sentry/include/SentryDateUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN
44

55
SENTRY_EXTERN NSDateFormatter *sentryGetIso8601FormatterWithMillisecondPrecision(void);
66

7-
SENTRY_EXTERN NSDate *sentry_fromIso8601String(NSString *string);
7+
SENTRY_EXTERN NSDate *_Nullable sentry_fromIso8601String(NSString *string);
88

99
SENTRY_EXTERN NSString *sentry_toIso8601String(NSDate *date);
1010

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import XCTest
2+
3+
final class SentryDateUtilsTests: XCTestCase {
4+
5+
func testFromIso8601String_WithEmptyInput_ReturnsNil() {
6+
XCTAssertNil(sentry_fromIso8601String(""))
7+
}
8+
9+
func testFromIso8601String_WithInvalidInput_ReturnsNil() {
10+
XCTAssertNil(sentry_fromIso8601String("not a date"))
11+
}
12+
13+
func testFromIso8601String_WithMillisecondPrecision_ReturnsCorrectDate() throws {
14+
// Precalculated date that matches the string below
15+
let expectedDate = Date(timeIntervalSince1970: 26_269_950.123000026)
16+
17+
let dateString = "1970-11-01T01:12:30.123Z"
18+
let date = try XCTUnwrap(sentry_fromIso8601String(dateString))
19+
20+
XCTAssertEqual(date, expectedDate)
21+
}
22+
}

Tests/SentryTests/Protocol/Codable/SentryDateCodableTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ final class SentryDateCodableTests: XCTestCase {
2525

2626
// The ISO8601 date format only supports milliseconds precision.
2727
// Therefore, we convert the ISO date string back to the date.
28-
let expectedDate = sentry_fromIso8601String(isoString)
29-
28+
let expectedDate = try XCTUnwrap(sentry_fromIso8601String(isoString))
29+
3030
let json = "{\"date\": \"\(isoString)\"}".data(using: .utf8)!
3131

3232
// Act

0 commit comments

Comments
 (0)