Skip to content

Commit

Permalink
Added LazyScriptNamePrefixedUrl.replace override (#1079)
Browse files Browse the repository at this point in the history
This is needed for LazyScriptNamePrefixedUrl to work correctly
with `urllib.parse`.

Python's `urllib.parse` started to call the `replace` method here:

https://bugs.python.org/issue43882
  • Loading branch information
cuu508 committed Nov 22, 2021
1 parent b855c68 commit 73eae6a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compressor/tests/test_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ def split(self, *args, **kwargs):
"""
return str(self).split(*args, **kwargs)

def replace(self, *args, **kwargs):
""" Override ``.replace()`` to make it work with ``{% static %}``.
In ``django.core.files.storage``, ``FileSystemStorage.url()`` passes
this object to ``urllib.parse.urljoin``.
In ``urrlib.parse``, the function that calls ``replace()`` is
``_remove_unsafe_bytes_from_url()``.
"""
return str(self).replace(*args, **kwargs)


@contextmanager
def script_prefix(new_prefix):
Expand Down

0 comments on commit 73eae6a

Please sign in to comment.