3232NSString *const kFIRDLParameterWeakMatchEndpoint = @" invitation_weakMatchEndpoint" ;
3333NSString *const kFIRDLParameterMatchMessage = @" match_message" ;
3434NSString *const kFIRDLParameterRequestIPVersion = @" request_ip_version" ;
35+ static NSSet *FIRDLCustomDomains = nil ;
3536
3637NSURL *FIRDLCookieRetrievalURL (NSString *urlScheme, NSString *bundleID) {
3738 static NSString *const kFDLBundleIDQueryParameterName = @" fdl_ios_bundle_id" ;
@@ -192,6 +193,23 @@ BOOL FIRDLOSVersionSupported(NSString *_Nullable systemVersion, NSString *minSup
192193 return timeZoneName;
193194}
194195
196+ BOOL FIRDLIsURLForWhiteListedCustomDomain (NSURL *_Nullable URL) {
197+ BOOL customDomainMatchFound = false ;
198+ for (NSURL *allowedCustomDomain in FIRDLCustomDomains) {
199+ // All custom domain host names should match at a minimum.
200+ if ([allowedCustomDomain.host isEqualToString: URL.host]) {
201+ // Next, do a string compare to check if the full path matches as well.
202+ if (([URL.absoluteString rangeOfString: allowedCustomDomain.absoluteString
203+ options: NSCaseInsensitiveSearch | NSAnchoredSearch]
204+ .location ) == 0 ) {
205+ customDomainMatchFound = true ;
206+ break ;
207+ }
208+ }
209+ }
210+ return customDomainMatchFound;
211+ }
212+
195213BOOL FIRDLCanParseUniversalLinkURL (NSURL *_Nullable URL) {
196214 // Handle universal links with format |https://goo.gl/app/<appcode>?<parameters>|.
197215 // Also support page.link format.
@@ -200,7 +218,11 @@ BOOL FIRDLCanParseUniversalLinkURL(NSURL *_Nullable URL) {
200218 // Handle universal links with format |https://<appcode>.app.goo.gl?<parameters>| and page.link.
201219 BOOL isDDLWithSubdomain =
202220 [URL.host hasSuffix: @" .app.goo.gl" ] || [URL.host hasSuffix: @" .page.link" ];
203- return isDDLWithAppcodeInPath || isDDLWithSubdomain;
221+
222+ // Handle universal links for custom domains.
223+ BOOL isDDLWithCustomDomain = FIRDLIsURLForWhiteListedCustomDomain (URL);
224+
225+ return isDDLWithAppcodeInPath || isDDLWithSubdomain || isDDLWithCustomDomain;
204226}
205227
206228BOOL FIRDLMatchesShortLinkFormat (NSURL *URL) {
@@ -227,4 +249,19 @@ BOOL FIRDLMatchesShortLinkFormat(NSURL *URL) {
227249 return matchMap[serverMatchTypeString] ?: @" none" ;
228250}
229251
252+ void FIRDLAddToWhiteListForCustomDomainsArray (NSArray *_Nonnull customDomains) {
253+ // Duplicates will be weeded out when converting to a set.
254+ NSMutableArray *validCustomDomains =
255+ [[NSMutableArray alloc ] initWithCapacity: customDomains.count];
256+ for (NSString *customDomainEntry in customDomains) {
257+ NSURL *customDomainURL = [NSURL URLWithString: customDomainEntry];
258+ // We require a valid scheme for each custom domain enumerated in the info.plist file.
259+ if (customDomainURL && customDomainURL.scheme ) {
260+ [validCustomDomains addObject: customDomainURL];
261+ }
262+ }
263+ // Duplicates will be weeded out when converting to a set.
264+ FIRDLCustomDomains = [NSSet setWithArray: validCustomDomains];
265+ }
266+
230267NS_ASSUME_NONNULL_END
0 commit comments