Fixed hidden form fields bug #1527

0.60.x
Simon Willison 2022-01-13 16:27:21 -08:00
rodzic 515f8d38eb
commit 3a0f7d6488
2 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -815,7 +815,7 @@ class TableView(RowTableShared):
if (
key.startswith("_")
and key not in ("_sort", "_search", "_next")
and not key.endswith("__exact")
and "__" not in key
):
for value in request.args.getlist(key):
form_hidden_args.append((key, value))

Wyświetl plik

@ -143,17 +143,29 @@ def test_existing_filter_redirects(app_client):
assert "?" not in response.headers["Location"]
def test_exact_parameter_results_in_correct_hidden_fields(app_client):
@pytest.mark.parametrize(
"qs,expected_hidden",
(
# Things that should be reflected in hidden form fields:
("_facet=_neighborhood", {"_facet": "_neighborhood"}),
("_where=1+=+1&_col=_city_id", {"_where": "1 = 1", "_col": "_city_id"}),
# Things that should NOT be reflected in hidden form fields:
(
"_facet=_neighborhood&_neighborhood__exact=Downtown",
{"_facet": "_neighborhood"},
),
("_facet=_neighborhood&_city_id__gt=1", {"_facet": "_neighborhood"}),
),
)
def test_reflected_hidden_form_fields(app_client, qs, expected_hidden):
# https://github.com/simonw/datasette/issues/1527
response = app_client.get(
"/fixtures/facetable?_facet=_neighborhood&_neighborhood__exact=Downtown"
)
response = app_client.get("/fixtures/facetable?{}".format(qs))
# In this case we should NOT have a hidden _neighborhood__exact=Downtown field
form = Soup(response.body, "html.parser").find("form")
hidden_inputs = {
input["name"]: input["value"] for input in form.select("input[type=hidden]")
}
assert hidden_inputs == {"_facet": "_neighborhood"}
assert hidden_inputs == expected_hidden
def test_empty_search_parameter_gets_removed(app_client):