From 65fcac5c49be089665d181aabd2a8a7f82758c31 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Tue, 8 Jun 2021 23:23:51 +0200 Subject: [PATCH] Fix encoding handling for file listing with py2 File listings with -l that contained files with umlauts or other special chars could break the directory listing. Hopefully one of the last python2 fixes before I drop support for this. --- ChangeLog | 1 + servefile/servefile.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 32dd8a8..286af8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ Unreleased SERVEFILE_SECONDARY_PORT * fixed broken redirect when filename contained umlauts or other characters that should have been quoted + * fixed broken special char handling in directory listing for python2 * drop python3.5 support diff --git a/servefile/servefile.py b/servefile/servefile.py index 7e7fd48..8bdbc34 100755 --- a/servefile/servefile.py +++ b/servefile/servefile.py @@ -542,7 +542,9 @@ class DirListingHandler(FileBaseHandler): self.send_header("Content-Length", str(len(listing))) self.send_header('Connection', 'close') self.end_headers() - self.wfile.write(listing.encode()) + if sys.version_info.major >= 3: + listing = listing.encode() + self.wfile.write(listing) def convertSize(self, size): for ext in "KMGT":