From 2a365b6156f7651e1b795cc88e128f288e4130d6 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 14 May 2018 19:09:09 -0300 Subject: [PATCH] path_with_added_args now works with multiple existing args --- datasette/utils.py | 4 ++-- tests/test_utils.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/datasette/utils.py b/datasette/utils.py index 0e0c388b..e5bdf589 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -149,10 +149,10 @@ def path_with_added_args(request, args, path=None): path = path or request.path if isinstance(args, dict): args = args.items() - arg_keys = set(a[0] for a in args) + args_to_remove = {k for k, v in args if v is None} current = [] for key, value in urllib.parse.parse_qsl(request.query_string): - if key not in arg_keys: + if key not in args_to_remove: current.append((key, value)) current.extend([ (key, value) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0d6bb2d1..bbae4f08 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -35,6 +35,9 @@ def test_urlsafe_components(path, expected): ('/?_facet=state&_facet=city&state=MI', ( ('city', 'Detroit'), ), '/?_facet=state&_facet=city&state=MI&city=Detroit'), + ('/?_facet=state&_facet=city', ( + ('_facet', 'planet_id'), + ), '/?_facet=state&_facet=city&_facet=planet_id'), ]) def test_path_with_added_args(path, added_args, expected): request = Request(