Skip to content

Only strip root_path from PATH_INFO at a path segment boundary - #602

Open
lprnmns wants to merge 1 commit into
django:mainfrom
lprnmns:wsgi-root-path-boundary
Open

lprnmns wants to merge 1 commit into
django:mainfrom
lprnmns:wsgi-root-path-boundary

Conversation

@lprnmns

@lprnmns lprnmns commented Oct 15, 2026 •

Copy link
Copy Markdown

WsgiToAsgiInstance.build_environ() strips root_path from the start of path with a plain startswith, so it also strips it when root_path is only a prefix of the first path segment:

scope = {"root_path": "/app", "path": "/application/foo", ...}
# SCRIPT_NAME = "/app", PATH_INFO = "lication/foo"

PATH_INFO then doesn't even start with /.

This only strips root_path when the path is exactly root_path or continues with / after it, which is the same rule Starlette uses in get_route_path. Otherwise PATH_INFO is left as the full path, the same as it already is for paths that don't start with root_path at all.

Tests: a parametrized test_script_name_segment_boundary covering an exact match, a trailing slash, a non-matching segment prefix (/base vs /basement/foo) and an empty root_path. The /basement case fails on main. The full test suite, black, isort and flake8 pass.

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.

1 participant