Skip to content

Commit 849701c

Browse files
committed
fix: preserve empty string values in query parameter tuples
Resolves issue where query parameters with explicit empty string values were ambiguously handled during URL serialization.
1 parent b5addb6 commit 849701c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

test_query_params.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import httpx
2+
import pytest
3+
4+
5+
def test_query_params_preserve_empty_string():
6+
params = [("filter", "active"), ("tag", "")]
7+
url = httpx.URL("https://example.com/api", params=params)
8+
assert str(url) == "https://example.com/api?filter=active&tag="
9+
10+
11+
def test_query_params_tuple_with_multiple_empty_values():
12+
params = [("key1", ""), ("key2", "value"), ("key3", "")]
13+
request = httpx.Request("GET", "https://example.com/items", params=params)
14+
assert str(request.url) == "https://example.com/items?key1=&key2=value&key3="
15+
16+
17+
def test_query_params_none_vs_empty_string():
18+
# None should omit value, empty string should preserve key=
19+
params_with_empty = [("key", "")]
20+
params_with_none = [("key", None)]
21+
22+
assert str(httpx.URL("https://example.com", params=params_with_empty)) == "https://example.com?key="
23+
assert str(httpx.URL("https://example.com", params=params_with_none)) == "https://example.com?key"

0 commit comments

Comments
 (0)