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

Queryparams incorrectly parsing arrays #30

Open
racinmat opened this issue Jun 24, 2021 · 2 comments
Open

Queryparams incorrectly parsing arrays #30

racinmat opened this issue Jun 24, 2021 · 2 comments

Comments

@racinmat
Copy link

Representing an array in query parameter is tricky and there is no single true way, but I think at least one of the often-used approaches should be supported.
Current behavior is:

julia> using URIs
julia> queryparams("foo=bar,qux")
Dict{String,String} with 1 entry:
  "foo" => "bar,qux"

julia> queryparams("foo[]=bar&foo[]=qux")
Dict{String,String} with 1 entry:
  "foo[]" => "qux"

julia> queryparams("foo=bar&foo=qux")
Dict{String,String} with 1 entry:
  "foo" => "qux"

julia> queryparams("foo%5B%5D=bar&foo%5B%5D=qux")
Dict{String,String} with 1 entry:
  "foo[]" => "qux"

I would expect all of them, or at least the ones with repeated foo to return an array instead of string with single value.
It would make the type-stability more complicated, because now it's Dict{String,String}, so accommodating arrays there would mean changing it probably to Dict{String,Union{Vector},String}}?
I'm not sure how the proper solution should look like, but we should not definitely lose parameters as the current behavior does.

@fredrikekre
Copy link
Member

There is a WIP PR for this here: JuliaWeb/HTTP.jl#433 (just need to decide the return type in case of multiple identical keys).

@jondea
Copy link

jondea commented Aug 26, 2023

This issue has just bit me while using Oxygen.jl. Any progress on this?

If anyone is coming here looking for a hacky solution, I used this workaround

function queryparamdict(req::HTTP.Request)
    d = Dict{String,Any}()
    params = queryparampairs(URI(req.target))
    for (key,value) in params
        if key  keys(d)
            d[key] = [d[key]; value]
        else
            d[key] = value
        end
    end
    return d
end

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