diff --git a/CHANGELOG.md b/CHANGELOG.md index 4248f725..73178142 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ## Unreleased: pdoc next +- Fix handling of URL-escaped module names ([#787](https://github.com/mitmproxy/pdoc/pull/787), @iFreilicht) ## 2024-12-12: pdoc 15.0.1 diff --git a/pdoc/web.py b/pdoc/web.py index d19ff7ae..3d66a3e8 100644 --- a/pdoc/web.py +++ b/pdoc/web.py @@ -14,6 +14,7 @@ import http.server import traceback from typing import Mapping +import urllib.parse import warnings import webbrowser @@ -60,6 +61,7 @@ def handle_request(self) -> str: return "Not Found: Please normalize all module separators to '/'." else: module_name = path.lstrip("/").removesuffix(".html").replace("/", ".") + module_name = urllib.parse.unquote(module_name) if module_name not in self.server.all_modules: self.send_response(404) self.send_header("content-type", "text/html") diff --git a/test/test_web.py b/test/test_web.py index c007d761..5905234c 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -69,6 +69,12 @@ def test_get_module(): ) +def test_get_module_url_escape_sequences(): + assert b"make_dataclass" in handle_request( + b"GET /%64atac%6Ca%73se%73.html HTTP/1.1\r\n\r\n" + ) + + def test_get_dependency(): assert b"a template engine written in pure Python" in handle_request( b"GET /jinja2.html HTTP/1.1\r\n\r\n"