Skip to content
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

Extract the query string first before parsing the parameters #35

Closed
wants to merge 2 commits into from

Conversation

gameldar
Copy link

@gameldar gameldar commented Aug 14, 2019

Description

Extract the query string from the URL before parsing it so that the value doesn't end up only in the last matching parameter.

Split the path at the first question mark before parsing the path and store the result in the query_string value of the match

Enable turning off the behaviour at the router level.

Motivation and Context

Closes #30

How Has This Been Tested?

Unit tests are implemented to cover the use cases

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Split the path at the first question mark before parsing the path and store the result in the query_string value of the match

Enable turning off the behaviour at the router level.
@gameldar gameldar force-pushed the 30-extract-query-string branch from 3850816 to 814c4be Compare August 14, 2019 15:09
@Nemo157 Nemo157 self-requested a review August 14, 2019 15:13
@Nemo157
Copy link
Contributor

Nemo157 commented Aug 17, 2019

This seems decent enough, but I was recently thinking about whether this crate might be used in wasm and be involved with client-side routing. If it does, then this would fail for a fragment containing a ? (e.g. /foo#bar?baz should have no query string and a fragment of bar?baz). And we would probably want to do something similar for the fragment.

An alternative might be to not do this and just document better that users need to be pre-parsing the url into components and only passing the path in to be routed, it looks like Tide at least is already doing this.

@gameldar
Copy link
Author

This seems decent enough, but I was recently thinking about whether this crate might be used in wasm and be involved with client-side routing. If it does, then this would fail for a fragment containing a ? (e.g. /foo#bar?baz should have no query string and a fragment of bar?baz). And we would probably want to do something similar for the fragment.

I did implement it as being optional, but on by default - so we could also potentially reverse the default too... but when implementing this I was checking out the specification for a URL in itself and the query string concept is only relevant to HTTP urls anyway. So on reflection I think you are correct in this:

An alternative might be to not do this and just document better that users need to be pre-parsing the url into components and only passing the path in to be routed, it looks like Tide at least is already doing this.

This is a library crate so it would be better to document that this is the expected input (and perhaps show an example of using it that way).

I'm planning on getting to the documentation this week - so I'll approach it in that way.

@gameldar gameldar closed this Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query string ends up in the last matching parameter's value
2 participants