Browse Source

Allow for pasteboard links with trailing slashes as valid custom domain links (#2220)

* Allow for pasteboard links with trailing slashes as valid custom domain links.
dmandar 7 years ago
parent
commit
09e49e867d

+ 1 - 1
Example/DynamicLinks/FDLBuilderTestAppObjC/ViewController.m

@@ -290,7 +290,7 @@ static NSArray *kParamsConfiguration;
   NSURL *link = [NSURL URLWithString:_paramValues[@"linkString"]];
   FIRDynamicLinkComponents *components =
       [FIRDynamicLinkComponents componentsWithLink:link
-                                   domainURIPrefix:_paramValues[@"https://domain"]];
+                                   domainURIPrefix:_paramValues[@"domainURIPrefix"]];
 
   FIRDynamicLinkGoogleAnalyticsParameters *analyticsParams =
       [FIRDynamicLinkGoogleAnalyticsParameters

+ 6 - 0
Example/DynamicLinks/Tests/FIRDynamicLinksTest.m

@@ -1032,6 +1032,12 @@ static void UnswizzleDynamicLinkNetworking() {
     @"https://a.firebase.com/mypath/mylink",  // Short FDL starting https://a.firebase.com/mypath
     @"https://a.firebase.com/mypath?link=abcd&test=1",  // Long FDL starting with
                                                         // https://a.firebase.com/mypath
+    @"https://a.firebase.com/mypath/?link=https://www.google.com&test=1"  // Long FDL coming from
+                                                                          // the app preview page.
+                                                                          // Note that the long FDL
+                                                                          // coming from the
+                                                                          // pasteboard has an extra
+                                                                          // trailing slash.
   ];
 
   for (NSString *urlString in urlStrings) {

+ 4 - 2
Firebase/DynamicLinks/Utilities/FDLUtilities.m

@@ -212,10 +212,12 @@ BOOL FIRDLIsURLForWhiteListedCustomDomain(NSURL *_Nullable URL) {
             ([urlStr characterAtIndex:domainURIPrefixStr.length] == '/' ||
              [urlStr characterAtIndex:domainURIPrefixStr.length] == '?')) {
           // Check if there are any more '/' after the first '/' or '?' trailing the
-          // domainURIPrefix.
+          // domainURIPrefix. This does not apply to unique match links copied from the clipboard.
+          // The clipboard links will have '?link=' after the domainURIPrefix.
           NSString *urlWithoutDomainURIPrefix =
               [urlStr substringFromIndex:domainURIPrefixStr.length + 1];
-          if ([urlWithoutDomainURIPrefix rangeOfString:@"/"].location == NSNotFound) {
+          if ([urlWithoutDomainURIPrefix rangeOfString:@"/"].location == NSNotFound ||
+              [urlWithoutDomainURIPrefix rangeOfString:@"?link="].location != NSNotFound) {
             customDomainMatchFound = true;
             break;
           }