-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Added ctx.QueryMulti() #288
Conversation
QueryMulti returns all values for the query string parameter in the url.
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you want to chat with us, join ons on Telegram https://t.me/gofiber |
ctx.go
Outdated
// QueryMulti returns all values for the query string parameter in the url. | ||
func(ctx *Ctx) QueryMulti(key string) (values []string) { | ||
valuesBytes := ctx.Fasthttp.QueryArgs().PeekMulti(key) | ||
values := make([]string, len(valuesBytes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/gofiber/fiber/pull/288/checks?check_run_id=613350878#step:4:19
[line 606 : column 9] - no new variables on left side of :=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Hi @monzarrugh ! Thanks for opening this Pull Request. I think it's a nice addition and I do see use cases of having multiple query parameters sharing the same key. However, I was unable to find any official documentation of having duplicate key entries in query strings. Commonly seen when having the same identifier and data type in query string, is adding the model name, i.e. Because this pull request does not share a default or common use case, I would suggest using the pointer to FastHTTP's RequestCtx Let us know if you have any questions! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems good to me
But I believe we must create unit tests in this case and added basic documents about it and smash both pull requests.
I added it because I found the need for it for my own use actually. The use case would be if you would implement filtering by multiple values for the same key (categories) for example. |
Hi @monzarrugh and welcome, thank you for trying to improve fiber by making a PR that contains a possible new feature for fiber. I do agree with @thomasvvugt, RFC 3986 has a section This means you may do what you like but at the same time duplicate keys have no standard when it comes to the order of the values ( I did some research on how other HTTP back-end's parse duplicate queries and found this report from OWASP that analyzed HTTP Parameter Pollution attacks. For your use case you could also use one query key and divide the values with Since it's use-case depended and we want to keep Fiber's API as clean as possible and inline with expressjs. I think that this would not have a valid purpose in this framework. If you are stuck with I hope this answered your question, thanks for your contribution! |
QueryMulti returns all values for the query string parameter in the url.