From 6684b76ab84c29d9ff74b8a1dc50737bd1c0d4e5 Mon Sep 17 00:00:00 2001 From: "wenjun.swj" Date: Fri, 15 Apr 2016 10:59:57 +0800 Subject: [PATCH] encode file name in Content-Disposition when it contains non-ascii characters --- notebook/nbconvert/handlers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notebook/nbconvert/handlers.py b/notebook/nbconvert/handlers.py index 8d8792d73..e5614956c 100644 --- a/notebook/nbconvert/handlers.py +++ b/notebook/nbconvert/handlers.py @@ -7,7 +7,7 @@ import io import os import zipfile -from tornado import web +from tornado import web, escape from ..base.handlers import ( IPythonHandler, FilesRedirectHandler, @@ -38,7 +38,7 @@ def respond_zip(handler, name, output, resources): # Headers zip_filename = os.path.splitext(name)[0] + '.zip' handler.set_header('Content-Disposition', - 'attachment; filename="%s"' % zip_filename) + 'attachment; filename="%s"' % escape.url_escape(zip_filename)) handler.set_header('Content-Type', 'application/zip') # Prepare the zip file @@ -112,7 +112,7 @@ class NbconvertFileHandler(IPythonHandler): if self.get_argument('download', 'false').lower() == 'true': filename = os.path.splitext(name)[0] + resources['output_extension'] self.set_header('Content-Disposition', - 'attachment; filename="%s"' % filename) + 'attachment; filename="%s"' % escape.url_escape(filename)) # MIME type if exporter.output_mimetype: