Skip to content

Commit dcdc426

Browse files
committed
Ensure urls do not contain backward slashes on windows (kimetrica#67)
1 parent d4f9b5b commit dcdc426

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

binary_database_files/settings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
from urllib.parse import urljoin
22

33
from django.conf import settings
44
from django.urls import reverse
@@ -14,7 +14,7 @@ def URL_METHOD_1(name):
1414
"""
1515
Construct file URL based on media URL.
1616
"""
17-
return os.path.join(settings.MEDIA_URL, name)
17+
return urljoin(settings.MEDIA_URL, name)
1818

1919

2020
def URL_METHOD_2(name):

binary_database_files/storage.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def url(self, name):
159159
We could also raise an error like the SFTP backend of django-storages is doing, but the relative URL is the
160160
previous behavior so we fall back to that.
161161
"""
162-
return "{}{}".format(self._base_url, settings.DATABASE_FILES_URL_METHOD(name))
162+
url_name = name.replace('\\', '/')
163+
return "{}{}".format(self._base_url, settings.DATABASE_FILES_URL_METHOD(url_name))
163164

164165
def size(self, name):
165166
"""Return the size of the file with filename `name` in bytes."""

0 commit comments

Comments
 (0)