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

Multi-value query-string parameters discard all but last #2882

Open
shivjm opened this issue Aug 26, 2024 · 2 comments · May be fixed by #2966
Open

Multi-value query-string parameters discard all but last #2882

shivjm opened this issue Aug 26, 2024 · 2 comments · May be fixed by #2966
Milestone

Comments

@shivjm
Copy link

shivjm commented Aug 26, 2024

Describe the bug
Passing a query string like ?param=a&param=b redirects the page (or rewrites the location) to ?param=b. This seems partially intentional since ParamsMap maps String to String, but as you can see in the example, serializing a form can itself produce multiple values.

Leptos Dependencies

leptos = { version = "0.6" }
leptos_axum = { version = "0.6", optional = true }
leptos_meta = { version = "0.6" }
leptos_router = { version = "0.6" }

To Reproduce
Steps to reproduce the behavior:

  1. Clone shivjm/leptos-multi-value-params-mwe.
  2. Run cargo leptos serve (or watch).
  3. Open localhost:3000.
  4. Check the boxes.
  5. Click on Submit.
  6. Note that the URL in the address bar and the query string provided by Leptos are correct but the ParamsMap is not.
  7. Either refresh the page or navigate to the same URL.
  8. Note that the URL in the address bar has dropped one value for the parameter.

Expected behavior
Multi-value parameters should be collected into a Vec or equivalent structure. I imagine this would have to be a breaking change since ParamsMap currently maps String to String.

Screenshots

@shivjm
Copy link
Author

shivjm commented Aug 27, 2024

While I don’t see any way around changing the type of the underlying LinearMap (that could be considered part of the public interface), I think ParamsMap itself could continue to work the same way and simply add a get_all method. I don’t know what to do about insert, though; I guess it could get an append counterpart, and then the struct would probably need something like replace or set for replacing all the values of a parameter.

@gbj gbj added this to the 0.7 milestone Sep 2, 2024
@kczimm
Copy link

kczimm commented Sep 11, 2024

It looks like LinearMap got replaced for type ParamsMapInner = Vec<(Cow<'static, str>, String)> however ParamsMap still acts like a map and replaces existing keys.

Params of the same name are totally valid. Should we instead have something like, type ParamsMapInner = Vec<(Cow<'static, str>, Vec<String>)> then?

@kczimm kczimm linked a pull request Sep 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants