这是indexloc提供的服务,不要输入任何密码
Skip to content

[Navigation] Make deep link path arguments to not include slash #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all 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 @@ -111,6 +111,26 @@ class NavDestinationAndroidTest {
.isEqualTo(99)
}

@Test
fun matchDeepLinkBestMatchPathTail() {
val destination = NoOpNavigator().createDestination()

destination.addArgument("id", stringArgument())
destination.addDeepLink("www.example.com/users/{id}")
destination.addDeepLink("www.example.com/users/{id}/posts")

val match = destination.matchDeepLink(
Uri.parse("https://www.example.com/users/u43/posts")
)

assertWithMessage("Deep link should match")
.that(match)
.isNotNull()
assertWithMessage("Deep link should extract id argument correctly")
.that(match?.matchingArgs?.getString("id"))
.isEqualTo("u43")
}

@Test
fun matchDeepLinkBestMimeType() {
val destination = NoOpNavigator().createDestination()
Expand Down Expand Up @@ -178,6 +198,18 @@ class NavDestinationAndroidTest {
.that(destination.hasDeepLink(deepLink)).isFalse()
}

@Test
fun testIsValidDeepLinkInvalidLinkPathTail() {
val destination = NoOpNavigator().createDestination()
destination.addArgument("testString", stringArgument())
destination.addDeepLink("android-app://androidx.navigation.test/{testString}")

val deepLink = Uri.parse("android-app://androidx.navigation.test/test/extra")

assertWithMessage("Deep link should not match")
.that(destination.hasDeepLink(deepLink)).isFalse()
}

@Test
fun addInDefaultArgs() {
val destination = NoOpNavigator().createDestination()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class NavDeepLink internal constructor(
arguments.add(argName)
// Use Pattern.quote() to treat the input string as a literal
uriRegex.append(Pattern.quote(uri.substring(appendPos, matcher.start())))
uriRegex.append("(.+?)")
uriRegex.append("([^/]+?)")
appendPos = matcher.end()
exactDeepLink = false
}
Expand Down