Strip whitespace from redirect paths. Fixes #1350

This commit is contained in:
Karl Hobley 2015-07-06 15:17:58 +01:00
parent dc6cdd2ba2
commit 97e489e959
2 changed files with 5 additions and 0 deletions

View file

@ -41,6 +41,9 @@ class Redirect(models.Model):
@staticmethod
def normalise_path(url):
# Strip whitespace
url = url.strip()
# Parse url
url_parsed = urlparse(url)

View file

@ -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