Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/qs_codec/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _parse_object(
root: str = chain[i]

if root == "[]" and options.parse_lists:
if options.allow_empty_lists and leaf == "":
if options.allow_empty_lists and (leaf == "" or (options.strict_null_handling and leaf is None)):
obj = []
else:
obj = list(leaf) if isinstance(leaf, (list, tuple)) else [leaf]
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/decode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def test_allows_empty_lists_in_obj_values(self) -> None:
assert decode("foo[]&bar=baz", DecodeOptions(allow_empty_lists=True)) == {"foo": [], "bar": "baz"}
assert decode("foo[]&bar=baz", DecodeOptions(allow_empty_lists=False)) == {"foo": [""], "bar": "baz"}

def test_allow_empty_lists_and_strict_null_handling(self) -> None:
assert decode("testEmptyList[]", DecodeOptions(strict_null_handling=True, allow_empty_lists=True)) == {
"testEmptyList": []
}

def test_parses_a_single_nested_string(self) -> None:
assert decode("a[b]=c") == {"a": {"b": "c"}}

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/encode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ def test_should_omit_map_key_value_pair_when_value_is_empty_list_and_when_asked(
assert encode({"a": [], "b": "zz"}, options=EncodeOptions(allow_empty_lists=False)) == "b=zz"
assert encode({"a": [], "b": "zz"}, options=EncodeOptions(allow_empty_lists=True)) == "a[]&b=zz"

def test_empty_list_with_strict_null_handling(self) -> None:
assert (
encode({"testEmptyList": []}, options=EncodeOptions(strict_null_handling=True, allow_empty_lists=True))
== "testEmptyList[]"
)

def test_encodes_a_nested_list_value(self) -> None:
assert (
encode(
Expand Down