From 2b4910fb1c532bc31aab4f3cbbbb8c282ea625bb Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Singh Date: Sat, 15 Aug 2026 15:01:59 +0530 Subject: [PATCH] fix: preserve empty query string values --- src/browserbase/_qs.py | 5 ++--- tests/test_qs.py | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/browserbase/_qs.py b/src/browserbase/_qs.py index 4127c19c..d3c34ce6 100644 --- a/src/browserbase/_qs.py +++ b/src/browserbase/_qs.py @@ -112,10 +112,9 @@ def _stringify_item( f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}" ) - serialised = self._primitive_value_to_str(value) - if not serialised: + if value is None: return [] - return [(key, serialised)] + return [(key, self._primitive_value_to_str(value))] def _primitive_value_to_str(self, value: PrimitiveData) -> str: # copied from httpx diff --git a/tests/test_qs.py b/tests/test_qs.py index b6d53dc8..19d4374c 100644 --- a/tests/test_qs.py +++ b/tests/test_qs.py @@ -16,6 +16,7 @@ def test_empty() -> None: def test_basic() -> None: assert stringify({"a": 1}) == "a=1" assert stringify({"a": "b"}) == "a=b" + assert stringify({"a": ""}) == "a=" assert stringify({"a": True}) == "a=true" assert stringify({"a": False}) == "a=false" assert stringify({"a": 1.23456}) == "a=1.23456" @@ -40,6 +41,7 @@ def test_nested_brackets() -> None: assert unquote(stringify({"a": {"b": "c", "d": "e", "f": "g"}})) == "a[b]=c&a[d]=e&a[f]=g" assert unquote(stringify({"a": {"b": {"c": {"d": "e"}}}})) == "a[b][c][d]=e" assert unquote(stringify({"a": {"b": True}})) == "a[b]=true" + assert unquote(stringify({"a": {"b": ""}})) == "a[b]=" @pytest.mark.parametrize("method", ["class", "function"]) @@ -59,6 +61,7 @@ def test_array_repeat() -> None: assert unquote(stringify({"a": {"b": [True, False]}})) == "a[b]=true&a[b]=false" assert unquote(stringify({"a": {"b": [True, False, None, True]}})) == "a[b]=true&a[b]=false&a[b]=true" assert unquote(stringify({"in": ["foo", {"b": {"c": ["d", "e"]}}]})) == "in=foo&in[b][c]=d&in[b][c]=e" + assert stringify({"in": [""]}) == "in=" @pytest.mark.parametrize("method", ["class", "function"])