Skip to content

Commit 53328b0

Browse files
authored
Version 1.32.0 (#130)
* Use ffi.buffer to better handle nulls * Call destructor in __deepcopy__ * Call ada_free_strings in URLSearchParams.get_all * Bump version to 1.32.0
1 parent 70fd4f6 commit 53328b0

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

ada_url/ada_adapter.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ def _get_obj(constructor, destructor, *args):
116116

117117

118118
def _get_str(x):
119-
ret = ffi.string(x.data, x.length).decode() if x.length else ''
120-
return ret
119+
return bytes(ffi.buffer(x.data, x.length)).decode() if x.length else ''
121120

122121

123122
class URL:
@@ -217,7 +216,7 @@ def __deepcopy__(self, memo):
217216
cls = self.__class__
218217
ret = cls.__new__(cls)
219218
super(URL, ret).__init__()
220-
ret.urlobj = lib.ada_copy(self.urlobj)
219+
ret.urlobj = _get_obj(lib.ada_copy, lib.ada_free, self.urlobj)
221220

222221
return ret
223222

@@ -397,14 +396,16 @@ def get(self, key: str) -> str:
397396
return _get_str(item)
398397

399398
def get_all(self, key: str) -> List[str]:
399+
ret = []
400400
key_bytes = key.encode()
401401
items = lib.ada_search_params_get_all(self.paramsobj, key_bytes, len(key_bytes))
402-
count = lib.ada_strings_size(items)
403-
404-
ret = []
405-
for i in range(count):
406-
value = _get_str(lib.ada_strings_get(items, i))
407-
ret.append(value)
402+
try:
403+
count = lib.ada_strings_size(items)
404+
for i in range(count):
405+
value = _get_str(lib.ada_strings_get(items, i))
406+
ret.append(value)
407+
finally:
408+
lib.ada_free_strings(items)
408409

409410
return ret
410411

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ada-url"
7-
version = "1.31.1"
7+
version = "1.32.0"
88
authors = [
99
{name = "Bo Bayles", email = "bo@bbayles.com"},
1010
]

tests/test_ada_url.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,13 @@ def test_replace_search_params(self):
535535
expected = 'key2=value3&key1=value4&key1=value5'
536536
self.assertEqual(actual, expected)
537537

538+
def test_null_handling(self):
539+
evil_input = 'admin\x00hidden=true&safe=value'
540+
params = SearchParams(evil_input)
541+
actual = list(params.keys())
542+
expected = ['admin\x00hidden', 'safe']
543+
self.assertEqual(actual, expected)
544+
538545

539546
class ParseTests(TestCase):
540547
def test_url_suite(self):

0 commit comments

Comments
 (0)