fix for wrong query string encoding when passed an empty :params input

Fixes https://github.com/HoneyryderChuck/httpx/issues/85
This commit is contained in:
HoneyryderChuck 2025-04-26 00:20:28 +01:00
parent 17c1090b7a
commit 0484dd76c8
2 changed files with 10 additions and 1 deletions

View File

@ -226,7 +226,7 @@ module HTTPX
return @query if defined?(@query)
query = []
if (q = @query_params)
if (q = @query_params) && !q.empty?
query << Transcoder::Form.encode(q)
end
query << @uri.query if @uri.query

View File

@ -12,6 +12,15 @@ module Requests
verify_uploaded(body, "url", build_uri("/#{meth}?q=this+is+a+test"))
end
define_method :"test_#{meth}_query_params_empty" do
uri = build_uri("/#{meth}")
response = HTTPX.send(meth, "#{uri}?foo=bar", params: {})
verify_status(response, 200)
body = json_body(response)
verify_uploaded(body, "args", "foo" => "bar")
verify_uploaded(body, "url", build_uri("/#{meth}?foo=bar"))
end
define_method :"test_#{meth}_query_nested_params" do
uri = build_uri("/#{meth}")
response = HTTPX.send(meth, uri, params: { "q" => { "a" => "z" }, "a" => %w[1 2], "b" => [] })