Fixed #24336 -- Made django.conf.urls.static() ignore all absolute URLs
This commit is contained in:
parent
cdcf4164be
commit
2a74ceb5f3
|
@ -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 [
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue