diff -r 7fca308bbf07 django/contrib/comments/views/utils.py
a
|
b
|
|
25 | 25 | if next is None: |
26 | 26 | next = urlresolvers.reverse(default_view) |
27 | 27 | if get_kwargs: |
| 28 | if '#' in next: |
| 29 | tmp = next.rsplit('#', 1) |
| 30 | next = tmp[0] |
| 31 | anchor = '#' + tmp[1] |
| 32 | else: |
| 33 | anchor = '' |
| 34 | |
28 | 35 | joiner = ('?' in next) and '&' or '?' |
29 | | next += joiner + urllib.urlencode(get_kwargs) |
| 36 | next += joiner + urllib.urlencode(get_kwargs) + anchor |
30 | 37 | return HttpResponseRedirect(next) |
31 | 38 | |
32 | 39 | def confirmation_view(template, doc="Display a confirmation view."): |
diff -r 7fca308bbf07 tests/regressiontests/comment_tests/tests/comment_view_tests.py
a
|
b
|
|
251 | 251 | broken_location = location + u"\ufffd" |
252 | 252 | response = self.client.get(broken_location) |
253 | 253 | self.assertEqual(response.status_code, 200) |
| 254 | |
| 255 | def testCommentNextWithQueryStringAndAnchor(self): |
| 256 | """ |
| 257 | The `next` key needs to handle already having a query string (#10585) |
| 258 | """ |
| 259 | a = Article.objects.get(pk=1) |
| 260 | data = self.getValidData(a) |
| 261 | data["next"] = "/somewhere/else/?foo=bar#baz" |
| 262 | data["comment"] = "This is another comment" |
| 263 | response = self.client.post("/post/", data) |
| 264 | location = response["Location"] |
| 265 | match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+#baz$", location) |
| 266 | self.failUnless(match != None, "Unexpected redirect location: %s" % location) |
254 | 267 | |
| 268 | |