aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamie Matthews2012-02-07 11:08:55 +0000
committerJamie Matthews2012-02-07 11:08:55 +0000
commit76a7d35813b637bb199a0d388468f9265f8adaf2 (patch)
tree63df8c8d3ef40dd4ece7d4e5295c092181ad9373
parent6207791af1702ec4a80d689b39ca4e4d1c9d8157 (diff)
downloaddjango-rest-framework-76a7d35813b637bb199a0d388468f9265f8adaf2.tar.bz2
Ensure duplicate "page" parameters are not created
Previously, URLObject.add_query_param was used to generate next/previous page links in PaginatorMixin. This resulted in (for example) page 2's "next" link having the params: ?page=2&page=3 Instead, URLObject.set_query_param should be used to replace the current value of the "page" parameter.
-rw-r--r--djangorestframework/mixins.py2
-rw-r--r--djangorestframework/tests/mixins.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py
index f4a9c998..836c3a59 100644
--- a/djangorestframework/mixins.py
+++ b/djangorestframework/mixins.py
@@ -679,7 +679,7 @@ class PaginatorMixin(object):
Constructs a url used for getting the next/previous urls
"""
url = URLObject.parse(self.request.get_full_path())
- url = url.add_query_param('page', page_number)
+ url = url.set_query_param('page', page_number)
limit = self.get_limit()
if limit != self.limit:
diff --git a/djangorestframework/tests/mixins.py b/djangorestframework/tests/mixins.py
index a7512efc..8268fdca 100644
--- a/djangorestframework/tests/mixins.py
+++ b/djangorestframework/tests/mixins.py
@@ -280,3 +280,12 @@ class TestPagination(TestCase):
self.assertTrue('foo=bar' in content['next'])
self.assertTrue('another=something' in content['next'])
self.assertTrue('page=2' in content['next'])
+
+ def test_duplicate_parameters_are_not_created(self):
+ """ Regression: ensure duplicate "page" parameters are not added to
+ paginated URLs. So page 1 should contain ?page=2, not ?page=1&page=2 """
+ request = self.req.get('/paginator/?page=1')
+ response = MockPaginatorView.as_view()(request)
+ content = json.loads(response.content)
+ self.assertTrue('page=2' in content['next'])
+ self.assertFalse('page=1' in content['next'])