Skip to content
Open
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
19 changes: 10 additions & 9 deletions ada_url/ada_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def _get_obj(constructor, destructor, *args):


def _get_str(x):
ret = ffi.string(x.data, x.length).decode() if x.length else ''
return ret
return bytes(ffi.buffer(x.data, x.length)).decode() if x.length else ''


class URL:
Expand Down Expand Up @@ -217,7 +216,7 @@ def __deepcopy__(self, memo):
cls = self.__class__
ret = cls.__new__(cls)
super(URL, ret).__init__()
ret.urlobj = lib.ada_copy(self.urlobj)
ret.urlobj = _get_obj(lib.ada_copy, lib.ada_free, self.urlobj)

return ret

Expand Down Expand Up @@ -396,14 +395,16 @@ def get(self, key: str) -> str:
return _get_str(item)

def get_all(self, key: str) -> List[str]:
ret = []
key_bytes = key.encode()
items = lib.ada_search_params_get_all(self.paramsobj, key_bytes, len(key_bytes))
count = lib.ada_strings_size(items)

ret = []
for i in range(count):
value = _get_str(lib.ada_strings_get(items, i))
ret.append(value)
try:
count = lib.ada_strings_size(items)
for i in range(count):
value = _get_str(lib.ada_strings_get(items, i))
ret.append(value)
finally:
lib.ada_free_strings(items)

return ret

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "ada-url"
version = "1.31.0"
version = "1.32.0"
authors = [
{name = "Bo Bayles", email = "bo@bbayles.com"},
]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_ada_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ def test_replace_search_params(self):
expected = 'key2=value3&key1=value4&key1=value5'
self.assertEqual(actual, expected)

def test_null_handling(self):
evil_input = 'admin\x00hidden=true&safe=value'
params = SearchParams(evil_input)
actual = list(params.keys())
expected = ['admin\x00hidden', 'safe']
self.assertEqual(actual, expected)


class ParseTests(TestCase):
def test_url_suite(self):
Expand Down
Loading