Skip to content

Commit 276e35f

Browse files
authored
Fixing the short url logic (#9005)
* Adding back the missed regex check for short links and correcting the test cases.
1 parent 86f79b5 commit 276e35f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

FirebaseDynamicLinks/Sources/Utilities/FDLUtilities.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ BOOL FIRDLMatchesShortLinkFormat(NSURL *URL) {
295295
// Path cannot be prefixed with /link/dismiss
296296
BOOL isDismiss = [[URL.path lowercaseString] hasPrefix:@"/link/dismiss"];
297297

298-
return hasPathOrCustomDomain && !isDismiss && canParse;
298+
// Checks short link format by having only one path after domain prefix.
299+
BOOL matchesRegularExpression =
300+
([URL.path rangeOfString:@"/[^/]+" options:NSRegularExpressionSearch].location != NSNotFound);
301+
302+
return hasPathOrCustomDomain && !isDismiss && canParse && matchesRegularExpression;
299303
}
300304

301305
NSString *FIRDLMatchTypeStringFromServerString(NSString *_Nullable serverMatchTypeString) {

FirebaseDynamicLinks/Tests/Unit/FIRDynamicLinksTest.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,6 @@ - (void)testFailMatchesShortLinkFormatForCustomDomains {
11981198
- (void)testPassMatchesShortLinkFormatForCustomDomains {
11991199
NSArray<NSString *> *urlStrings = @[
12001200
@"https://google.com/xyz", @"https://google.com/xyz/?link=https://somedomain",
1201-
@"https://google.com?link=https://somedomain", @"https://google.com/?link=https://somedomain",
12021201
@"https://google.com/xyz?link=https://somedomain",
12031202
@"https://google.com/xyz/?link=https://somedomain", @"https://google.com/one/xyz",
12041203
@"https://google.com/one/xyz?link=https://somedomain",
@@ -1606,7 +1605,6 @@ - (void)testValidCustomDomainNames {
16061605
@"https://google.com/one?", // Short FDL starting with 'https://google.com'
16071606
@"https://google.com/one/mylink", // Short FDL starting with 'https://google.com/one'
16081607
@"https://a.firebase.com/mypath/mylink", // Short FDL starting https://a.firebase.com/mypath
1609-
@"https://google.com?link=https://somedomain", @"https://google.com/?link=https://somedomain",
16101608
@"https://google.com/somepath?link=https://somedomain",
16111609
@"https://google.com/somepath/?link=https://somedomain",
16121610
@"https://google.com/somepath/somepath2?link=https://somedomain",

0 commit comments

Comments
 (0)