Skip to content

Commit

Permalink
Handle non ascii folder name (#72)
Browse files Browse the repository at this point in the history
* fix #71 Error when downloading an floder not named in English
  • Loading branch information
eastonsuo authored Oct 13, 2021
1 parent 350e0c8 commit bb49d4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jupyter_archive/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.utils import url2path, url_path_join
from tornado import ioloop, web
from urllib.parse import quote

SUPPORTED_FORMAT = [
"zip",
Expand Down Expand Up @@ -142,6 +143,7 @@ async def get(self, archive_path, include_body=False):

archive_path = pathlib.Path(cm.root_dir) / url2path(archive_path)
archive_filename = f"{archive_path.name}.{archive_format}"
archive_filename = quote(archive_filename)

self.log.info("Prepare {} for archiving and downloading.".format(archive_filename))
self.set_header("content-type", "application/octet-stream")
Expand Down
8 changes: 8 additions & 0 deletions jupyter_archive/tests/test_archive_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"download-archive-dir/test2.txt",
"download-archive-dir/test1.txt",
"download-archive-dir/test3.md",
"download-archive-dir/中文文件夹/中文.txt",
},
),
(
Expand All @@ -27,6 +28,7 @@
"download-archive-dir/test2.txt",
"download-archive-dir/test1.txt",
"download-archive-dir/test3.md",
"download-archive-dir/中文文件夹/中文.txt",
"download-archive-dir/.test4.md",
"download-archive-dir/.test-hidden-folder/test5.md",
},
Expand All @@ -38,6 +40,7 @@
"download-archive-dir/test2.txt",
"download-archive-dir/test1.txt",
"download-archive-dir/test3.md",
"download-archive-dir/中文文件夹/中文.txt",
"download-archive-dir/symlink-test-dir/test6.md",
},
),
Expand All @@ -48,6 +51,7 @@
"download-archive-dir/test2.txt",
"download-archive-dir/test1.txt",
"download-archive-dir/test3.md",
"download-archive-dir/中文文件夹/中文.txt",
"download-archive-dir/.test4.md",
"download-archive-dir/.test-hidden-folder/test5.md",
"download-archive-dir/symlink-test-dir/test6.md",
Expand Down Expand Up @@ -85,6 +89,10 @@ async def test_download(jp_fetch, jp_root_dir, followSymlinks, download_hidden,
hidden_folder.mkdir(parents=True)
(hidden_folder / "test5.md").write_text("hello5")

non_ascii_folder = archive_dir_path / "中文文件夹"
non_ascii_folder.mkdir(parents=True)
(non_ascii_folder / "中文.txt").write_text("你好")

symlink_dir_path = jp_root_dir / "symlink-archive-dir"
symlink_dir_path.mkdir(parents=True)
(symlink_dir_path / "test6.md").write_text("hello6")
Expand Down

0 comments on commit bb49d4e

Please sign in to comment.