Skip to content

URL-encode paths when serving a redirect#3001

Merged
oprypin merged 3 commits intomkdocs:masterfrom
blueswen:fix-utf-8-site_url
Oct 13, 2022
Merged

URL-encode paths when serving a redirect#3001
oprypin merged 3 commits intomkdocs:masterfrom
blueswen:fix-utf-8-site_url

Conversation

@blueswen
Copy link
Copy Markdown
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

This comment was marked as abuse.

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.

2 participants