From 06d4fe254d22a9f5315609f3a0908aef527a5d4c Mon Sep 17 00:00:00 2001 From: Waweic Date: Tue, 6 Mar 2018 17:49:20 +0100 Subject: [PATCH] Implement recommendations by sampsyo Implemented all recommendations. --- beetsplug/web/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/beetsplug/web/__init__.py b/beetsplug/web/__init__.py index 29bb6b27a..3cf43ed56 100644 --- a/beetsplug/web/__init__.py +++ b/beetsplug/web/__init__.py @@ -229,14 +229,16 @@ def item_file(item_id): try: unicode_item_path = util.text_string(item.path) except (UnicodeDecodeError, UnicodeEncodeError): - unicode_item_path = u"fallback" + os.path.splitext(item_path)[1] + unicode_item_path = util.displayable_path(item.path) + base_filename = os.path.basename(unicode_item_path) try: # Imitate http.server behaviour - os.path.basename(unicode_item_path).encode("latin-1", "strict") - safe_filename = os.path.basename(unicode_item_path) - except (UnicodeDecodeError, UnicodeEncodeError): - safe_filename = unidecode(os.path.basename(unicode_item_path)) + base_filename.encode("latin-1", "strict") + except UnicodeEncodeError: + safe_filename = unidecode(base_filename) + else: + safe_filename = base_filename response = flask.send_file( item_path,