Skip to content

[Navigation] Check that all required arguments are present in the link - #204

Closed
osipxd wants to merge 4 commits into
androidx:androidx-mainfrom
osipxd:185527157-check-required-args-in-deep-links
Closed

[Navigation] Check that all required arguments are present in the link#204
osipxd wants to merge 4 commits into
androidx:androidx-mainfrom
osipxd:185527157-check-required-args-in-deep-links

Conversation

@osipxd

@osipxd osipxd commented Jun 20, 2021

Copy link
Copy Markdown
Contributor

Proposed Changes

Currently, we can open a destination with a link that doesn't contain the required arguments. In this case, we will get a crash in runtime. This commit adds check that all required arguments are present in the link.

After this change, deep links will require to contain all required arguments for a destination. Links not containing all required arguments will be ignored.

Testing

Test: ./gradlew test connectedCheck

Issues Fixed

Fixes: 185527157

@google-cla google-cla Bot added the cla: yes label Jun 20, 2021
Comment on lines +315 to +324
val missingRequiredArguments = arguments.filterValues { !it.isDefaultValuePresent }
.keys
.filter { it !in navDeepLink.arguments }
require(missingRequiredArguments.isEmpty()) {
"Deep link ${navDeepLink.uriPattern} can't be used to open destination $this.\n" +
"Following required arguments are missing: $missingRequiredArguments"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would be great to have a check like this to make sure deep links will be able to open this destination. But I'm not sure I've selected the right place for this. We can add the required parameters after deepLink is added to bypass this validation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe also add validation after a new argument was added?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure why it wasn't caught in github, but this is failing a number of navigation-runtime test.

Screen Shot 2021-08-03 at 4 10 59 PM

I am thinking that our sample xml isn't realistic enough and we may need to add an argument to the deepLink that goes to second_test.

@osipxd osipxd Aug 16, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jbw0033, I've fixed tests in the latest commit (8339589), can you take a look if I did it right?

@osipxd osipxd changed the title Check that all required arguments are present in the link [Navigation] Check that all required arguments are present in the link Jun 20, 2021

@sanura-njaka sanura-njaka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi Osip, can you please rebase your changes?

@osipxd
osipxd force-pushed the 185527157-check-required-args-in-deep-links branch from 482b430 to 32f58c4 Compare June 22, 2021 09:11
@osipxd

osipxd commented Jun 22, 2021

Copy link
Copy Markdown
Contributor Author

Hi Osip, can you please rebase your changes?

Done

@dlam

dlam commented Jun 30, 2021

Copy link
Copy Markdown
Contributor

Looks like there's a conflict - could you rebase your changes again?

@osipxd

osipxd commented Jul 5, 2021

Copy link
Copy Markdown
Contributor Author

Yes, I'll rebase it soon

@osipxd
osipxd force-pushed the 185527157-check-required-args-in-deep-links branch 2 times, most recently from fa397d1 to 9010b95 Compare July 18, 2021 07:20
@osipxd

osipxd commented Jul 20, 2021

Copy link
Copy Markdown
Contributor Author

Requires #210 to be merged first

@osipxd
osipxd force-pushed the 185527157-check-required-args-in-deep-links branch 2 times, most recently from 2a2d790 to 967d504 Compare July 21, 2021 09:56
@osipxd
osipxd force-pushed the 185527157-check-required-args-in-deep-links branch from 967d504 to e11326c Compare July 29, 2021 06:05
@osipxd

osipxd commented Jul 29, 2021

Copy link
Copy Markdown
Contributor Author

It failed again after rebase. Something related to navigation-compose module:

Could not determine the dependencies of task ':navigation:navigation-compose:compileReleaseJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':navigation:navigation-compose:releaseCompileClasspath'.

@dlam, can you take a look?

@jbw0033

jbw0033 commented Jul 29, 2021

Copy link
Copy Markdown

I think this is on our side since the compose 1.0.1 release isn't yet available. I'll check on getting it resolved.

@jbw0033
jbw0033 self-requested a review July 29, 2021 22:08
osipxd added 3 commits August 16, 2021 09:33
Currently we can open destination with link that doesn't contain required arguments. In this case we will get crash in runtime. This commit adds check that all required arguments are present in link.

Test: ./gradlew test connectedCheck
Fixes: 185527157
@osipxd
osipxd force-pushed the 185527157-check-required-args-in-deep-links branch from e11326c to 803d037 Compare August 16, 2021 06:33
@osipxd
osipxd requested a review from jbw0033 August 16, 2021 10:35
@osipxd
osipxd force-pushed the 185527157-check-required-args-in-deep-links branch from d1cced0 to 8339589 Compare August 16, 2021 10:39
@osipxd
osipxd deleted the 185527157-check-required-args-in-deep-links branch August 18, 2021 06:52
@jbw0033

jbw0033 commented Aug 18, 2021

Copy link
Copy Markdown

Thank you for bearing with us to get this PR out @osipxd!

@svenjacobs

Copy link
Copy Markdown

I believe this change introduced a bug. Please see here.

@osipxd

osipxd commented Sep 11, 2021

Copy link
Copy Markdown
Contributor Author

@svenjacobs, looks like a duplicate of 198689811. This issue is already fixed. I think it will be included in the next version.

harryzz pushed a commit to harryzz/compose-multiplatform-core that referenced this pull request Jul 28, 2026
…e link

## Proposed Changes

Currently, we can open a destination with a link that doesn't contain the required arguments. In this case, we will get a crash in runtime. This commit adds check that all required arguments are present in the link.

After this change, deep links will require to contain all required arguments for a destination. Links not containing all required arguments will be ignored.

## Testing

Test: ./gradlew test connectedCheck

## Issues Fixed

Fixes: [185527157](https://issuetracker.google.com/issues/185527157)

This is an imported pull request from androidx#204.

Resolves JetBrains#204
Github-Pr-Head-Sha: 8339589
GitOrigin-RevId: 0df2dce
Change-Id: Ie43ace08a5ace320820479f41750712476dae880
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants