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

URL-encode paths when serving a redirect #3001

Merged
merged 3 commits into from Oct 13, 2022

Conversation

blueswen
Copy link
Contributor

When the site_url contains utf-8 characters (e.g. http://fake.domain/測試) and uses mkdocs server to serve doc, visiting localhost:8000 will cause wsgi encoding error when doing 302 redirects. The error log is as follows:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/wsgiref/handlers.py", line 185, in finish_response
    self.finish_content()
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/wsgiref/handlers.py", line 324, in finish_content
    self.send_headers()
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/wsgiref/handlers.py", line 347, in send_headers
    self._write(bytes(self.headers))
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/wsgiref/headers.py", line 142, in __bytes__
    return str(self).encode('iso-8859-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 11-12: ordinal not in range(256)

URL encoding those 302 paths could solve this issue. A minimal reproducible mkdocs.yaml is as follows:

site_name: My Docs
site_url: http://fake.domain/測試

@oprypin
Copy link
Contributor

oprypin commented Oct 13, 2022

Thanks

@oprypin oprypin changed the title URL encode utf-8 path for 302 URL-encode paths when serving a redirect Oct 13, 2022
@oprypin oprypin merged commit 79fa445 into mkdocs:master Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants