Skip to content

Commit d839950

Browse files
committed
Encode the topic name when subscribing
This should address the issue filed at: firebase/quickstart-ios#242, where a topic name containing a `%` character was failing. It turns out that the topic name was never being url-encoded.
1 parent 5d984b0 commit d839950

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Firebase/Messaging/FIRMessagingTopicOperation.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,20 @@ - (void)performSubscriptionChange {
165165
[request setValue:appIdentifier forHTTPHeaderField:@"app"];
166166
[request setValue:self.checkinService.versionInfo forHTTPHeaderField:@"info"];
167167

168+
// Topic can contain special characters (like `%`) so encode the value.
169+
NSCharacterSet *characterSet = [NSCharacterSet URLQueryAllowedCharacterSet];
170+
NSString *encodedTopic =
171+
[self.topic stringByAddingPercentEncodingWithAllowedCharacters:characterSet];
172+
168173
NSMutableString *content = [NSMutableString stringWithFormat:
169174
@"sender=%@&app=%@&device=%@&"
170175
@"app_ver=%@&X-gcm.topic=%@&X-scope=%@",
171176
self.token,
172177
appIdentifier,
173178
deviceAuthID,
174179
FIRMessagingCurrentAppVersion(),
175-
self.topic,
176-
self.topic];
180+
encodedTopic,
181+
encodedTopic];
177182

178183
if (self.action == FIRMessagingTopicActionUnsubscribe) {
179184
[content appendString:@"&delete=true"];

0 commit comments

Comments
 (0)