-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Incorrect documented use of qs
when dealing with complex query parameters
#4058
Comments
I'm having the exact same issue, after update I've created a gist here to easily recreate the problem, when reaching http://localhost:3333/test?status=a,b Without any validator, The problem seems to happen somewhere here: Lines 169 to 171 in 5796cd9
as Line 147 in 5796cd9
Hope this help. |
Having the same issue. According to ljharb/qs#357 the Maybe there could be an extra string parameter to For example, changing the Lines 144 to 149 in d064f9c
like this
And add then add search parameter to the caller here Line 236 in d064f9c
|
note: |
const Hapi = require('@hapi/hapi');
const Qs = require('qs');
const server = Hapi.server({
port: 3000,
host: 'localhost',
query: {
parser: (query) => Qs.parse(query)
}
});
server.route({ path: '/', method: 'GET', handler: (request) => request.query });
server.start(); and... $ curl http://localhost:3000/?s=4
> {"s":"4"}
$ curl http://localhost:3000/?s[a]=4
> {"s":{"a":"4"}} I don't see a problem. |
I believe the issue is if you parse with the “comma” array format enabled, fwiw. |
Yes, it doesn't work for parsing arrays, even with
|
Thanks @ljharb. I consider this a qs/usage issue. hapi is not going to implement custom logic. If qs does not want to properly support its own API where you can pass either a string or an object with each key=value pair literals, then someone has to write a wrapper that implements the comma stuff... |
Context
What are you trying to achieve or the steps to reproduce ?
I was trying to use qs as recommended by hapi's documentation (see https://hapi.dev/tutorials/routing/?lang=en_US#query) however unsurprisingly, it did not work.
The documentation recommends something like this:
The problem is that the
query
parameter inserver.options.query.parser
is an object not a string (See). For that reason,Qs.parse(query)
is wrong sinceQs.parse
expects a string.To get things working, I am manually building a query string; something like:
Is there an undocumented way to receive the raw query string or to convert
request.query
to a string?I already opened an issue in the hapi.dev repo (hapijs/hapi.dev#297) but I was directed to report here.
The text was updated successfully, but these errors were encountered: