0001-misc-clean-URIs-missing-a-trailing-slash-40801.patch
combo/public/views.py | ||
---|---|---|
487 | 487 |
hierarchy_ids.append(page.id) |
488 | 488 | |
489 | 489 |
if not url.endswith('/') and settings.APPEND_SLASH: |
490 |
# this is useful to allow /login, /manage, and other non-page |
|
491 |
# URLs to work. |
|
492 |
return HttpResponsePermanentRedirect(url + '/') |
|
490 |
# this is useful to allow /login, /manage, and other non-page URLs to |
|
491 |
# work. re.sub is used to replace repeated slashes by single ones, |
|
492 |
# this prevents a double slash at the start to redirect to a |
|
493 |
# //whatever service, which would be interpreted as http[s]://whatever/. |
|
494 |
return HttpResponsePermanentRedirect(re.sub('/+', '/', url) + '/') |
|
493 | 495 | |
494 | 496 |
if page is None: |
495 | 497 |
redirect = Redirect.objects.filter(old_url=url).last() |
tests/test_public.py | ||
---|---|---|
958 | 958 |
resp = app.get('/', status=200) |
959 | 959 |
assert 'id="unique"' in resp.text |
960 | 960 |
assert 'id="dup"' not in resp.text |
961 | ||
962 | ||
963 |
def test_missing_trailing_slashes(app): |
|
964 |
# redirect to path with slash |
|
965 |
assert urlparse.urlparse(app.get('/login', status=301).location).path == '/login/' |
|
966 |
assert urlparse.urlparse(app.get('/foo', status=301).location).path == '/foo/' |
|
967 |
# don't be tricked by double slashes |
|
968 |
assert urlparse.urlparse(app.get('//foo', status=301).location).path == '/foo/' |
|
961 |
- |