diff --git a/datasette/utils.py b/datasette/utils.py index 6138d353e4..118d9bd714 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -151,10 +151,9 @@ def path_with_added_args(request, args, path=None): args = args.items() arg_keys = set(a[0] for a in args) current = [] - for key, values in request.args.items(): - current.extend( - [(key, value) for value in values if key not in arg_keys] - ) + for key, value in urllib.parse.parse_qsl(request.query_string): + if key not in arg_keys: + current.append((key, value)) current.extend([ (key, value) for key, value in args diff --git a/tests/test_utils.py b/tests/test_utils.py index cc987723d9..3f51f87d5e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -29,9 +29,12 @@ def test_urlsafe_components(path, expected): ('/foo?bar=1&bar=2', {'baz': 3}, '/foo?bar=1&bar=2&baz=3'), ('/foo?bar=1', {'bar': None}, '/foo'), # Test order is preserved - ('/?_facet=prim_state&_facet=area_name', { - 'prim_state': 'GA' - }, '/?_facet=prim_state&_facet=area_name&prim_state=GA'), + ('/?_facet=prim_state&_facet=area_name', ( + ('prim_state', 'GA'), + ), '/?_facet=prim_state&_facet=area_name&prim_state=GA'), + ('/?_facet=state&_facet=city&state=MI', ( + ('city', 'Detroit'), + ), '/?_facet=state&_facet=city&state=MI&city=Detroit'), ]) def test_path_with_added_args(path, added_args, expected): request = Request(