From 97e489e959875a1976e3a2cb593877e6de14b498 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Mon, 6 Jul 2015 15:17:58 +0100 Subject: [PATCH] Strip whitespace from redirect paths. Fixes #1350 --- wagtail/wagtailredirects/models.py | 3 +++ wagtail/wagtailredirects/tests.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/wagtail/wagtailredirects/models.py b/wagtail/wagtailredirects/models.py index 36cc6294a..d11f93160 100644 --- a/wagtail/wagtailredirects/models.py +++ b/wagtail/wagtailredirects/models.py @@ -41,6 +41,9 @@ class Redirect(models.Model): @staticmethod def normalise_path(url): + # Strip whitespace + url = url.strip() + # Parse url url_parsed = urlparse(url) diff --git a/wagtail/wagtailredirects/tests.py b/wagtail/wagtailredirects/tests.py index dcb88f35b..9fcba66fa 100644 --- a/wagtail/wagtailredirects/tests.py +++ b/wagtail/wagtailredirects/tests.py @@ -20,6 +20,8 @@ class TestRedirects(TestCase): self.assertEqual(path, normalise_path('Hello/world.html/?foo=Bar&Baz=quux2')) # Trailing slashes are ignored self.assertEqual(path, normalise_path('/Hello/world.html?foo=Bar&Baz=quux2#cool')) # Fragments are ignored self.assertEqual(path, normalise_path('/Hello/world.html?Baz=quux2&foo=Bar')) # Order of query string parameters are ignored + self.assertEqual(path, normalise_path(' /Hello/world.html?foo=Bar&Baz=quux2')) # Leading whitespace + self.assertEqual(path, normalise_path('/Hello/world.html?foo=Bar&Baz=quux2 ')) # Trailing whitespace # Test against different paths self.assertNotEqual(path, normalise_path('/hello/world.html?foo=Bar&Baz=quux2')) # 'hello' is lowercase