Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1049,4 +1049,72 @@ class NavDeepLinkTest {
.that(matchArgs?.getInt("id"))
.isEqualTo(id)
}

@Test
fun deepLinkCaseInsensitiveDomain() {
Comment thread
bentrengrove marked this conversation as resolved.
Resolved
val deepLinkString = DEEP_LINK_EXACT_HTTP
val deepLink = NavDeepLink(deepLinkString)

val deepLinkUpper = deepLinkString.toUpperCase()
assertThat(deepLink.matches(Uri.parse(deepLinkUpper)))
}

@Test
fun deepLinkCaseInsensitiveDomainRegexMatching() {
Comment thread
bentrengrove marked this conversation as resolved.
Resolved
val deepLinkArgument = "$DEEP_LINK_EXACT_HTTPS/users/{id}/posts"
val deepLink = NavDeepLink(deepLinkArgument)

val id = 2
val matchArgs = deepLink.getMatchingArguments(
Uri.parse("${DEEP_LINK_EXACT_HTTPS.toUpperCase()}/users/${id}/posts"),
mapOf("id" to intArgument())
)
assertWithMessage("Args should not be null")
.that(matchArgs)
.isNotNull()
assertWithMessage("Args should contain the id")
.that(matchArgs?.getInt("id"))
.isEqualTo(id)
}

@Test
fun deepLinkCaseInsensitiveArguments() {
Comment thread
bentrengrove marked this conversation as resolved.
Resolved
val deepLinkArgument = "$DEEP_LINK_EXACT_HTTPS/users/{id}/posts"
val deepLink = NavDeepLink(deepLinkArgument)

val id = 2
val matchArgs = deepLink.getMatchingArguments(
Uri.parse(deepLinkArgument
.replace("{id}", id.toString())
.replace("users", "Users")
),
mapOf("id" to intArgument())
)
assertWithMessage("Args should not be null")
.that(matchArgs)
.isNotNull()
assertWithMessage("Args should contain the id")
.that(matchArgs?.getInt("id"))
.isEqualTo(id)
}

@Test
fun deepLinkCaseSensitiveParams() {
Comment thread
bentrengrove marked this conversation as resolved.
Resolved
val deepLinkString = "$DEEP_LINK_EXACT_HTTP/?myParam={param}"
val deepLink = NavDeepLink(deepLinkString)

val param = 2
val deepLinkUpper = deepLinkString
.replace("myParam", "MyParam")
Comment thread
bentrengrove marked this conversation as resolved.
Resolved
.replace("{param}", param.toString())
val matchArgs = deepLink.getMatchingArguments(Uri.parse(deepLinkUpper),
mapOf("param" to intArgument()))

assertWithMessage("Args should be not be null")
.that(matchArgs)
.isNotNull()
assertWithMessage("Args bundle should be empty")
.that(matchArgs!!.isEmpty)
Comment thread
bentrengrove marked this conversation as resolved.
Resolved
.isTrue()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public class NavDeepLink internal constructor(
// specifically escape any .* instances to ensure
// they are still treated as wildcards in our final regex
val finalRegex = uriRegex.toString().replace(".*", "\\E.*\\Q")
pattern = Pattern.compile(finalRegex)
pattern = Pattern.compile(finalRegex, Pattern.CASE_INSENSITIVE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianhanniballake Since this is on the finalRegex, it is making the entire pattern including params case insensitive, but based on the test above, it looks like params still aren't matching, which is what we want. Wanted your thoughts on this method, vs always checking the domain in the lowercase or something similar.

}
if (mimeType != null) {
val mimeTypePattern = Pattern.compile("^[\\s\\S]+/[\\s\\S]+$")
Expand Down