Skip to content
Snippets Groups Projects
Commit 9c9f6708 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch '196-fix-filepath-encoding' into 'develop'

Resolve "404 for files with special utf-8-chars"

Closes #196

See merge request funkwhale/funkwhale!189
parents d8cbed5a 1937b816
No related branches found
No related tags found
No related merge requests found
......@@ -230,7 +230,7 @@ def get_file_path(audio_file):
'MUSIC_DIRECTORY_PATH to serve in-place imported files'
)
path = '/music' + audio_file.replace(prefix, '', 1)
return settings.PROTECT_FILES_PATH + path
return (settings.PROTECT_FILES_PATH + path).encode('utf-8')
if t == 'apache2':
try:
path = audio_file.path
......@@ -241,7 +241,7 @@ def get_file_path(audio_file):
'You need to specify MUSIC_DIRECTORY_SERVE_PATH and '
'MUSIC_DIRECTORY_PATH to serve in-place imported files'
)
path = audio_file.replace(prefix, serve_path, 1)
path = audio_file.replace(prefix, serve_path, 1).encode('utf-8')
return path
......
......@@ -104,6 +104,24 @@ def test_serve_file_in_place(
assert response[headers[proxy]] == expected
@pytest.mark.parametrize('proxy,serve_path,expected', [
('apache2', '/host/music', '/host/music/hello/worldéà.mp3'),
('apache2', '/app/music', '/app/music/hello/worldéà.mp3'),
('nginx', '/host/music', '/_protected/music/hello/worldéà.mp3'),
('nginx', '/app/music', '/_protected/music/hello/worldéà.mp3'),
])
def test_serve_file_in_place_utf8(
proxy, serve_path, expected, factories, api_client, settings):
settings.PROTECT_AUDIO_FILES = False
settings.PROTECT_FILE_PATH = '/_protected/music'
settings.REVERSE_PROXY_TYPE = proxy
settings.MUSIC_DIRECTORY_PATH = '/app/music'
settings.MUSIC_DIRECTORY_SERVE_PATH = serve_path
path = views.get_file_path('/app/music/hello/worldéà.mp3')
assert path == expected.encode('utf-8')
@pytest.mark.parametrize('proxy,serve_path,expected', [
('apache2', '/host/music', '/host/media/tracks/hello/world.mp3'),
# apache with container not supported yet
......
In-place imported tracks non-ascii characters don't break reverse-proxy serving (#196)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment