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

[FEATURE] Support multi-value query string parameters #754

Open
1 task done
silverskater opened this issue Mar 29, 2024 · 3 comments
Open
1 task done

[FEATURE] Support multi-value query string parameters #754

silverskater opened this issue Mar 29, 2024 · 3 comments

Comments

@silverskater
Copy link

silverskater commented Mar 29, 2024

Is there an existing feature request for this?

  • I have searched the existing feature requests

Is your feature request related to a problem? Please describe.

When using a multi-value query string parameter only the first value is checked.

Url ENDPOINT?sections=90&sections=130 with this check:

r.Queries("sections", "130")

It doesn't match, and it should because the only key-value required matches, but as it only checks the first it encounters (sections=90 in this case), it determines it doesn't match.
getURLQuery() only looks for the first query key: findFirstQueryKey().

Describe the solution that you would like.

Multi-value query params like sections=90&sections=130 should be matched by both commands from below, regardless of the order in the query string:

r.Queries("sections", "130")
r.Queries("sections", "90", "sections", "130")

Describe alternatives you have considered.

No response

Anything else?

This issue came up here: friendsofgo/killgrave#164

@Ranveer777
Copy link

@silverskater For multi-value query params use r.Queries("sections", "{sections}"). It will allow you to pass any and n number of sections in query.

You can also refer

mux/route.go

Line 400 in de7178d

// - {name} matches anything until the next slash.
for the usecase of Queries function.

Also, to restrict the value of sections in query params to 130 and 90 use r.Queries("sections", "{sections:(?:90|130)}")

@silverskater
Copy link
Author

thank you @Ranveer777 this is exactly what we need!

@joanlopez
Copy link

joanlopez commented Jun 13, 2024

Hey,

I don't think that's the same logic as having support for multi-value queries, @Ranveer777, I think what you're suggesting is just doing the trick with a pattern (regexp).

For instance, how would you define an endpoint that explicitly requires "both" values, not just "any"?

Thanks!

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

No branches or pull requests

3 participants