Skip to content

Commit 548eefe

Browse files
Add limits as constants and dispatch all completion blocks to global queue.
1 parent b2de614 commit 548eefe

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
@"FIRRemoteConfigActivateNotification";
5151
static NSNotificationName FIRRolloutsStateDidChangeNotificationName =
5252
@"FIRRolloutsStateDidChangeNotification";
53+
/// Maximum allowed length for a custom signal key (in characters).
54+
static const NSUInteger FIRRemoteConfigCustomSignalsMaxKeyLength = 250;
55+
/// Maximum allowed length for a string value in custom signals (in characters).
56+
static const NSUInteger FIRRemoteConfigCustomSignalsMaxStringValueLength = 500;
57+
/// Maximum number of custom signals allowed.
58+
static const NSUInteger FIRRemoteConfigCustomSignalsMaxCount = 100;
5359

5460
/// Listener for the get methods.
5561
typedef void (^FIRRemoteConfigListener)(NSString *_Nonnull, NSDictionary *_Nonnull);
@@ -272,17 +278,21 @@ - (void)setCustomSignals:(nullable NSDictionary<NSString *, NSObject *> *)custom
272278
return;
273279
}
274280

275-
if (key.length > 250 ||
276-
([value isKindOfClass:[NSString class]] && [(NSString *)value length] > 500)) {
281+
if (key.length > FIRRemoteConfigCustomSignalsMaxKeyLength ||
282+
([value isKindOfClass:[NSString class]] &&
283+
[(NSString *)value length] > FIRRemoteConfigCustomSignalsMaxStringValueLength)) {
277284
if (completionHandler) {
278285
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
279-
NSError *error = [NSError errorWithDomain:FIRRemoteConfigCustomSignalsErrorDomain
280-
code:FIRRemoteConfigCustomSignalsErrorLimitExceeded
281-
userInfo:@{
282-
NSLocalizedDescriptionKey :
283-
@"Custom signal keys and string values must be "
284-
@"250 and 500 characters or less respectively."
285-
}];
286+
NSError *error = [NSError
287+
errorWithDomain:FIRRemoteConfigCustomSignalsErrorDomain
288+
code:FIRRemoteConfigCustomSignalsErrorLimitExceeded
289+
userInfo:@{
290+
NSLocalizedDescriptionKey : [NSString
291+
stringWithFormat:@"Custom signal keys and string values must be "
292+
@"%lu and %lu characters or less respectively.",
293+
FIRRemoteConfigCustomSignalsMaxKeyLength,
294+
FIRRemoteConfigCustomSignalsMaxStringValueLength]
295+
}];
286296
completionHandler(error);
287297
});
288298
}
@@ -305,14 +315,16 @@ - (void)setCustomSignals:(nullable NSDictionary<NSString *, NSObject *> *)custom
305315
}
306316

307317
// Check the size limit.
308-
if (newCustomSignals.count > 100) {
318+
if (newCustomSignals.count > FIRRemoteConfigCustomSignalsMaxCount) {
309319
if (completionHandler) {
310320
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
311321
NSError *error = [NSError
312322
errorWithDomain:FIRRemoteConfigCustomSignalsErrorDomain
313323
code:FIRRemoteConfigCustomSignalsErrorLimitExceeded
314324
userInfo:@{
315-
NSLocalizedDescriptionKey : @"Custom signals count exceeds the limit of 100."
325+
NSLocalizedDescriptionKey : [NSString
326+
stringWithFormat:@"Custom signals count exceeds the limit of %lu.",
327+
FIRRemoteConfigCustomSignalsMaxCount]
316328
}];
317329
completionHandler(error);
318330
});
@@ -325,7 +337,7 @@ - (void)setCustomSignals:(nullable NSDictionary<NSString *, NSObject *> *)custom
325337
self->_settings.customSignals = newCustomSignals;
326338
}
327339
if (completionHandler) {
328-
dispatch_async(dispatch_get_main_queue(), ^{
340+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
329341
completionHandler(nil);
330342
});
331343
}

0 commit comments

Comments
 (0)