diff options
author | Riz <rsattar@gmail.com> | 2017-08-30 15:38:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-30 15:38:43 -0700 |
commit | e00eaa8f0e9a2b6601d0dff4e71a9131788397f6 (patch) | |
tree | 2c0a0b2c01ac8fa6aa60cd6188a36e9a7394ad66 /Firebase/Messaging | |
parent | 5d984b0611ee74c760bdd4c24c27379ace454c7b (diff) |
Encode the topic name when subscribing (#220)
This should address the issue filed at: https://github.com/firebase/quickstart-ios/issues/242, where a topic name containing a `%` character was failing. It turns out that the topic name was never being url-encoded.
Diffstat (limited to 'Firebase/Messaging')
-rw-r--r-- | Firebase/Messaging/FIRMMessageCode.h | 1 | ||||
-rw-r--r-- | Firebase/Messaging/FIRMessagingTopicOperation.m | 17 |
2 files changed, 16 insertions, 2 deletions
diff --git a/Firebase/Messaging/FIRMMessageCode.h b/Firebase/Messaging/FIRMMessageCode.h index 5a30f84..6afc1bb 100644 --- a/Firebase/Messaging/FIRMMessageCode.h +++ b/Firebase/Messaging/FIRMMessageCode.h @@ -166,6 +166,7 @@ typedef NS_ENUM(NSInteger, FIRMessagingMessageCode) { kFIRMessagingMessageCodeTopicOption000 = 17000, // I-FCM017000 kFIRMessagingMessageCodeTopicOption001 = 17001, // I-FCM017001 kFIRMessagingMessageCodeTopicOption002 = 17002, // I-FCM017002 + kFIRMessagingMessageCodeTopicOptionTopicEncodingFailed = 17003, // I-FCM017003 // FIRMessagingUtilities.m kFIRMessagingMessageCodeUtilities000 = 18000, // I-FCM018000 kFIRMessagingMessageCodeUtilities001 = 18001, // I-FCM018001 diff --git a/Firebase/Messaging/FIRMessagingTopicOperation.m b/Firebase/Messaging/FIRMessagingTopicOperation.m index 955c4a6..90760eb 100644 --- a/Firebase/Messaging/FIRMessagingTopicOperation.m +++ b/Firebase/Messaging/FIRMessagingTopicOperation.m @@ -165,6 +165,19 @@ NSString *FIRMessagingSubscriptionsServer() { [request setValue:appIdentifier forHTTPHeaderField:@"app"]; [request setValue:self.checkinService.versionInfo forHTTPHeaderField:@"info"]; + // Topic can contain special characters (like `%`) so encode the value. + NSCharacterSet *characterSet = [NSCharacterSet URLQueryAllowedCharacterSet]; + NSString *encodedTopic = + [self.topic stringByAddingPercentEncodingWithAllowedCharacters:characterSet]; + if (encodedTopic == nil) { + // The transformation was somehow not possible, so use the original topic. + FIRMessagingLoggerWarn(kFIRMessagingMessageCodeTopicOptionTopicEncodingFailed, + @"Unable to encode the topic '%@' during topic subscription change. " + @"Please ensure that the topic name contains only valid characters.", + self.topic); + encodedTopic = self.topic; + } + NSMutableString *content = [NSMutableString stringWithFormat: @"sender=%@&app=%@&device=%@&" @"app_ver=%@&X-gcm.topic=%@&X-scope=%@", @@ -172,8 +185,8 @@ NSString *FIRMessagingSubscriptionsServer() { appIdentifier, deviceAuthID, FIRMessagingCurrentAppVersion(), - self.topic, - self.topic]; + encodedTopic, + encodedTopic]; if (self.action == FIRMessagingTopicActionUnsubscribe) { [content appendString:@"&delete=true"]; |