File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515
1616import django
1717from django .conf import global_settings
18- from django .core .exceptions import ImproperlyConfigured , ValidationError
19- from django .core .validators import URLValidator
18+ from django .core .exceptions import ImproperlyConfigured
2019from django .utils .deprecation import RemovedInDjango40Warning
2120from django .utils .functional import LazyObject , empty
2221
@@ -124,14 +123,8 @@ def _add_script_prefix(value):
124123 Useful when the app is being served at a subpath and manually prefixing
125124 subpath to STATIC_URL and MEDIA_URL in settings is inconvenient.
126125 """
127- # Don't apply prefix to valid URLs.
128- try :
129- URLValidator ()(value )
130- return value
131- except (ValidationError , AttributeError ):
132- pass
133- # Don't apply prefix to absolute paths.
134- if value .startswith ('/' ):
126+ # Don't apply prefix to absolute paths and URLs.
127+ if value .startswith (('http://' , 'https://' , '/' )):
135128 return value
136129 from django .urls import get_script_prefix
137130 return '%s%s' % (get_script_prefix (), value )
Original file line number Diff line number Diff line change @@ -16,3 +16,9 @@ Bugfixes
1616* Fixed a bug in Django 3.1 that caused a crash when processing middlewares in
1717 an async context with a middleware that raises a ``MiddlewareNotUsed``
1818 exception (:ticket:`32299`).
19+
20+ * Fixed a regression in Django 3.1 that caused the incorrect prefixing of
21+ ``STATIC_URL`` and ``MEDIA_URL`` settings, by the server-provided value of
22+ ``SCRIPT_NAME`` (or ``/`` if not set), when set to a URL specifying the
23+ protocol but without a top-level domain, e.g. ``http://myhost/``
24+ (:ticket:`32304`).
Original file line number Diff line number Diff line change @@ -577,10 +577,12 @@ def set_script_name(self, val):
577577 set_script_prefix (val )
578578
579579 def test_not_prefixed (self ):
580- # Don't add SCRIPT_NAME prefix to valid URLs, absolute paths or None.
580+ # Don't add SCRIPT_NAME prefix to absolute paths, URLs, or None.
581581 tests = (
582582 '/path/' ,
583583 'http://myhost.com/path/' ,
584+ 'http://myhost/path/' ,
585+ 'https://myhost/path/' ,
584586 None ,
585587 )
586588 for setting in ('MEDIA_URL' , 'STATIC_URL' ):
You can’t perform that action at this time.
0 commit comments