From 2a74ceb5f371c1083bfc9b95e093543ba09eb20f Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 23 Jul 2018 18:32:46 +0200 Subject: [PATCH] Fixed #24336 -- Made django.conf.urls.static() ignore all absolute URLs --- django/conf/urls/static.py | 3 ++- tests/view_tests/tests/test_static.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/django/conf/urls/static.py b/django/conf/urls/static.py index 150f4ffd3f..fa83645b9d 100644 --- a/django/conf/urls/static.py +++ b/django/conf/urls/static.py @@ -1,4 +1,5 @@ import re +from urllib.parse import urlsplit from django.conf import settings from django.core.exceptions import ImproperlyConfigured @@ -19,7 +20,7 @@ def static(prefix, view=serve, **kwargs): """ if not prefix: raise ImproperlyConfigured("Empty static prefix not permitted") - elif not settings.DEBUG or '://' in prefix: + elif not settings.DEBUG or urlsplit(prefix).netloc: # No-op if not in debug mode or a non-local prefix. return [] return [ diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py index 03cb19ea02..3154ce1703 100644 --- a/tests/view_tests/tests/test_static.py +++ b/tests/view_tests/tests/test_static.py @@ -153,8 +153,9 @@ class StaticHelperTest(StaticTests): static('') def test_special_prefix(self): - """No URLs are served if prefix contains '://'.""" - self.assertEqual(static('http://'), []) + """No URLs are served if prefix contains a netloc part.""" + self.assertEqual(static('http://example.org'), []) + self.assertEqual(static('//example.org'), []) class StaticUtilsTests(unittest.TestCase):