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
Improve usage of format strings #687
Conversation
case 0: | ||
fallthrough | ||
default: | ||
return String.localizedStringWithFormat(format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still are passing dynamic string to a format here, we should use regular localizedString(forKey:
method instead
@@ -304,6 +304,7 @@ extension LocalNotificationDispatcherTests { | |||
XCTAssertEqual(self.application.scheduledLocalNotifications.count, 1) | |||
XCTAssertEqual(self.notificationDelegate.receivedLocalNotifications.count, 0) | |||
guard let notification = self.application.scheduledLocalNotifications.first else { return XCTFail() } | |||
print(notification.alertBody!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably needs to go away:)
Codecov Report
@@ Coverage Diff @@
## develop #687 +/- ##
==========================================
+ Coverage 82.23% 82.4% +0.16%
==========================================
Files 173 173
Lines 12358 12344 -14
==========================================
+ Hits 10163 10172 +9
+ Misses 2195 2172 -23
Continue to review full report at Codecov.
|
Diff with previous: 142.0.7...142.0.8 Commits: b7a969f Improve usage of format strings (#687)
What's new in this PR?
Issues
We have some usage of format strings where it is possible to construct incorrect format strings if great care is not taken when using the localization methods.
Solutions
Issue 1:
ZMUserSession+UserNotificationCategories.m
Here we are passing format strings as variables down a chain of methods which can be risky if the key is not used as expected. We can fix this by resolving the localized string at the top level and pass it down instead.
issue 2:
ZMLocalNotificationLocalization.h
Here we expose several localization API method as an extension on
NSString
. These methods however only work with a certain set of localization strings defined inPush.strings
. Knowing which methods work together with which localization strings requires careful inspection of the code and is easy to get wrong.We will solve this replacing these methods with an enum representing every case of possible push notifications. This enum will then expose methods for creating the necessary localized strings which will always return a valid result.