diff --git a/datasette/app.py b/datasette/app.py index 9c0d29f1..fc1e8dfd 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -431,6 +431,8 @@ class TableView(BaseView): filter_column = special_args['_filter_column'] filter_op = special_args.get('_filter_op') or '' filter_value = special_args.get('_filter_value') or '' + if '__' in filter_op: + filter_op, filter_value = filter_op.split('__', 1) return self.redirect(request, path_with_added_args(request, { '{}__{}'.format(filter_column, filter_op): filter_value, '_filter_column': None, diff --git a/tests/test_app.py b/tests/test_app.py index 5df5ea25..003b5aca 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -249,6 +249,16 @@ def test_add_filter_redirects(app_client): assert response.status == 302 assert response.headers['Location'].endswith('?content__startswith=x&foo=bar') + # Test that op with a __x suffix overrides the filter value + path = path_base + '?' + urllib.parse.urlencode({ + '_filter_column': 'content', + '_filter_op': 'isnull__5', + '_filter_value': 'x' + }) + response = app_client.get(path, allow_redirects=False, gather_request=False) + assert response.status == 302 + assert response.headers['Location'].endswith('?content__isnull=5') + TABLES = ''' CREATE TABLE simple_primary_key (