Skip to content

Commit bb49d4e

Browse files
authored
Handle non ascii folder name (#72)
* fix #71 Error when downloading an floder not named in English
1 parent 350e0c8 commit bb49d4e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

jupyter_archive/handlers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from jupyter_server.base.handlers import JupyterHandler
88
from jupyter_server.utils import url2path, url_path_join
99
from tornado import ioloop, web
10+
from urllib.parse import quote
1011

1112
SUPPORTED_FORMAT = [
1213
"zip",
@@ -142,6 +143,7 @@ async def get(self, archive_path, include_body=False):
142143

143144
archive_path = pathlib.Path(cm.root_dir) / url2path(archive_path)
144145
archive_filename = f"{archive_path.name}.{archive_format}"
146+
archive_filename = quote(archive_filename)
145147

146148
self.log.info("Prepare {} for archiving and downloading.".format(archive_filename))
147149
self.set_header("content-type", "application/octet-stream")

jupyter_archive/tests/test_archive_handler.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"download-archive-dir/test2.txt",
1919
"download-archive-dir/test1.txt",
2020
"download-archive-dir/test3.md",
21+
"download-archive-dir/中文文件夹/中文.txt",
2122
},
2223
),
2324
(
@@ -27,6 +28,7 @@
2728
"download-archive-dir/test2.txt",
2829
"download-archive-dir/test1.txt",
2930
"download-archive-dir/test3.md",
31+
"download-archive-dir/中文文件夹/中文.txt",
3032
"download-archive-dir/.test4.md",
3133
"download-archive-dir/.test-hidden-folder/test5.md",
3234
},
@@ -38,6 +40,7 @@
3840
"download-archive-dir/test2.txt",
3941
"download-archive-dir/test1.txt",
4042
"download-archive-dir/test3.md",
43+
"download-archive-dir/中文文件夹/中文.txt",
4144
"download-archive-dir/symlink-test-dir/test6.md",
4245
},
4346
),
@@ -48,6 +51,7 @@
4851
"download-archive-dir/test2.txt",
4952
"download-archive-dir/test1.txt",
5053
"download-archive-dir/test3.md",
54+
"download-archive-dir/中文文件夹/中文.txt",
5155
"download-archive-dir/.test4.md",
5256
"download-archive-dir/.test-hidden-folder/test5.md",
5357
"download-archive-dir/symlink-test-dir/test6.md",
@@ -85,6 +89,10 @@ async def test_download(jp_fetch, jp_root_dir, followSymlinks, download_hidden,
8589
hidden_folder.mkdir(parents=True)
8690
(hidden_folder / "test5.md").write_text("hello5")
8791

92+
non_ascii_folder = archive_dir_path / "中文文件夹"
93+
non_ascii_folder.mkdir(parents=True)
94+
(non_ascii_folder / "中文.txt").write_text("你好")
95+
8896
symlink_dir_path = jp_root_dir / "symlink-archive-dir"
8997
symlink_dir_path.mkdir(parents=True)
9098
(symlink_dir_path / "test6.md").write_text("hello6")

0 commit comments

Comments
 (0)