diff --git a/src/anthropic/_qs.py b/src/anthropic/_qs.py index 4127c19c6..670ee5680 100644 --- a/src/anthropic/_qs.py +++ b/src/anthropic/_qs.py @@ -112,9 +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 [] + serialised = self._primitive_value_to_str(value) return [(key, serialised)] def _primitive_value_to_str(self, value: PrimitiveData) -> str: diff --git a/tests/test_qs.py b/tests/test_qs.py index 564a41e61..43a5486ab 100644 --- a/tests/test_qs.py +++ b/tests/test_qs.py @@ -20,6 +20,7 @@ def test_basic() -> None: assert stringify({"a": False}) == "a=false" assert stringify({"a": 1.23456}) == "a=1.23456" assert stringify({"a": None}) == "" + assert stringify({"a": ""}) == "a=" @pytest.mark.parametrize("method", ["class", "function"]) @@ -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"]) @@ -58,6 +60,7 @@ def test_array_repeat() -> None: assert unquote(stringify({"in": ["foo", "bar"]})) == "in=foo&in=bar" 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({"a": {"b": ["", None, "c"]}})) == "a[b]=&a[b]=c" assert unquote(stringify({"in": ["foo", {"b": {"c": ["d", "e"]}}]})) == "in=foo&in[b][c]=d&in[b][c]=e"