Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serving files/paths with Unicode characters #2464

Merged
merged 1 commit into from Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion mkdocs/livereload/__init__.py
Expand Up @@ -200,7 +200,9 @@ def serve_request(self, environ, start_response):
return [error_content]

def _serve_request(self, environ, start_response):
path = environ["PATH_INFO"]
# https://bugs.python.org/issue16679
# https://github.com/bottlepy/bottle/blob/f9b1849db4/bottle.py#L984
path = environ["PATH_INFO"].encode("latin-1").decode("utf-8", "ignore")

m = re.fullmatch(r"/livereload/([0-9]+)/[0-9]+", path)
if m:
Expand Down
17 changes: 17 additions & 0 deletions mkdocs/tests/livereload_tests.py
Expand Up @@ -304,6 +304,23 @@ def test_serves_modified_index(self, site_dir):
_, output = do_request(server, "GET /foo/")
self.assertRegex(output, fr"^<body>bbb{SCRIPT_REGEX}</body>$")

@tempdir({"я.html": "<body>aaa</body>", "测试2/index.html": "<body>bbb</body>"})
def test_serves_with_unicode_characters(self, site_dir):
with testing_server(site_dir) as server:
_, output = do_request(server, "GET /я.html")
self.assertRegex(output, fr"^<body>aaa{SCRIPT_REGEX}</body>$")
_, output = do_request(server, "GET /%D1%8F.html")
self.assertRegex(output, fr"^<body>aaa{SCRIPT_REGEX}</body>$")

with self.assertLogs("mkdocs.livereload"):
headers, _ = do_request(server, "GET /%D1.html")
self.assertEqual(headers["_status"], "404 Not Found")

_, output = do_request(server, "GET /测试2/")
self.assertRegex(output, fr"^<body>bbb{SCRIPT_REGEX}</body>$")
_, output = do_request(server, "GET /%E6%B5%8B%E8%AF%952/index.html")
self.assertRegex(output, fr"^<body>bbb{SCRIPT_REGEX}</body>$")

@tempdir()
def test_serves_js(self, site_dir):
with testing_server(site_dir) as server:
Expand Down