mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
Don't strip empty query params when paginating (#4260)
This commit is contained in:
parent
1d26b398ad
commit
7466b61e62
|
@ -7,7 +7,7 @@ def replace_query_param(url, key, val):
|
|||
parameters of the URL, and return the new URL.
|
||||
"""
|
||||
(scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
|
||||
query_dict = urlparse.parse_qs(query)
|
||||
query_dict = urlparse.parse_qs(query, keep_blank_values=True)
|
||||
query_dict[key] = [val]
|
||||
query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
|
||||
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
|
||||
|
@ -19,7 +19,7 @@ def remove_query_param(url, key):
|
|||
parameters of the URL, and return the new URL.
|
||||
"""
|
||||
(scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
|
||||
query_dict = urlparse.parse_qs(query)
|
||||
query_dict = urlparse.parse_qs(query, keep_blank_values=True)
|
||||
query_dict.pop(key, None)
|
||||
query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
|
||||
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
|
||||
|
|
|
@ -108,6 +108,17 @@ class TestPaginationIntegration:
|
|||
'count': 50
|
||||
}
|
||||
|
||||
def test_empty_query_params_are_preserved(self):
|
||||
request = factory.get('/', {'page': 2, 'filter': ''})
|
||||
response = self.view(request)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.data == {
|
||||
'results': [12, 14, 16, 18, 20],
|
||||
'previous': 'http://testserver/?filter=',
|
||||
'next': 'http://testserver/?filter=&page=3',
|
||||
'count': 50
|
||||
}
|
||||
|
||||
def test_404_not_found_for_zero_page(self):
|
||||
request = factory.get('/', {'page': '0'})
|
||||
response = self.view(request)
|
||||
|
|
Loading…
Reference in New Issue
Block a user