Skip to content

Commit

Permalink
🐛 decode: avoid a crash with comma=True, charset=Charset.LATIN1, in…
Browse files Browse the repository at this point in the history
…terpret_numeric_entities=True
  • Loading branch information
techouse committed Aug 29, 2024
1 parent 33778e7 commit 718fde7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/qs_codec/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def _parse_query_string_values(value: str, options: DecodeOptions) -> t.Dict[str
)

if val and options.interpret_numeric_entities and charset == Charset.LATIN1:
val = _interpret_numeric_entities(val) # type: ignore [arg-type]
val = _interpret_numeric_entities(
val if isinstance(val, str) else ",".join(val) if isinstance(val, (list, tuple)) else str(val)
) # type: ignore [arg-type]

if "[]=" in part:
val = [val] if isinstance(val, (list, tuple)) else val
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/decode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ def test_does_not_interpret_numeric_entities_in_iso_8859_1_when_interpret_numeri
DecodeOptions(charset=Charset.LATIN1, interpret_numeric_entities=False),
) == {"foo": "☺"}

def test_interpret_numeric_entities_with_comma_true_and_iso_8859_1_charset_does_not_crash(self) -> None:
assert decode(
f"b&a[]=1,{self.url_encoded_num_smiley}",
DecodeOptions(comma=True, charset=Charset.LATIN1, interpret_numeric_entities=True),
) == {"b": "", "a": ["1,☺"]}

def test_does_not_interpret_numeric_entities_when_the_charset_is_utf_8_even_when_interpret_numeric_entities(
self,
) -> None:
Expand Down

0 comments on commit 718fde7

Please sign in to comment.