diff --git a/auquotidien/modules/formpage.py b/auquotidien/modules/formpage.py index fa8c0e0..11da23b 100644 --- a/auquotidien/modules/formpage.py +++ b/auquotidien/modules/formpage.py @@ -18,6 +18,11 @@ from wcs.qommon import emails OldFormPage = wcs.forms.root.FormPage class AlternateFormPage(OldFormPage): + def __call__(self): + # Fix missing trailing slash; lose query string on purpose. + path = quixote.get_path() + return quixote.redirect(path + "/", permanent=True) + def form_side(self, *args, **kwargs): form_side_html = OldFormPage.form_side(self, *args, **kwargs) # add a 'Steps' title diff --git a/auquotidien/modules/root.py b/auquotidien/modules/root.py index be002d3..2af917d 100644 --- a/auquotidien/modules/root.py +++ b/auquotidien/modules/root.py @@ -287,6 +287,10 @@ class AlternateRootDirectory(OldRootDirectory): except KeyError: pass else: + if len(path) == 1: + # category with missing trailing slash, redirect. + path = quixote.get_path() + return quixote.redirect(path + "/", permanent=True) return FormsRootDirectory(cat)._q_traverse(path[1:]) raise e diff --git a/tests/test_user_pages.py b/tests/test_user_pages.py index 1e7611c..8e7b3c0 100644 --- a/tests/test_user_pages.py +++ b/tests/test_user_pages.py @@ -135,6 +135,25 @@ def test_form_category_redirection(): resp = get_app(pub).get('/foobar/') assert resp.location.endswith('/baz/foobar/') + # check missing trailing slashs are ok + resp = get_app(pub).get('/foobar') + assert resp.location.endswith('/baz/foobar') + resp = resp.follow() + assert resp.location.endswith('/baz/foobar/') + + # even if there's a query string + resp = get_app(pub).get('/foobar?test=1') + assert resp.location.endswith('/baz/foobar?test=1') + resp = resp.follow() + assert resp.location.endswith('/baz/foobar/') + + # check direct category access without trailing slash + resp = get_app(pub).get('/baz') + assert resp.location.endswith('/baz/') + resp = get_app(pub).get('/baz?test=1') + assert resp.location.endswith('/baz/') + + def test_form_and_category_same_slug(): Category.wipe() cat = Category(name='foobar')