Skip to content

Fix PurePath.match intercepting absolute shebang paths#349

Open
mcexit wants to merge 1 commit into
python:mainfrom
mcexit:patch-1
Open

Fix PurePath.match intercepting absolute shebang paths#349
mcexit wants to merge 1 commit into
python:mainfrom
mcexit:patch-1

Conversation

@mcexit
Copy link
Copy Markdown

@mcexit mcexit commented May 24, 2026

Fixes #348
Addresses #307 and #91

Per #345, resubmitting now that the issue has been filed.

This gates virtual alias matching and wildcard string-slicing behind an is_name_only check so explicit absolute paths cleanly fall through to _find_on_path.

…bare name rules

`PurePath.match()` performs right-aligned suffix matching, which caused absolute shebang paths (e.g., `C:\uv\python.exe`) to inadvertently evaluate true for bare names like `python.exe` or `python*.exe`.

This resulted in two critical bugs:

1. Virtual environment paths were hijacked by the `is_default` trap, falling back to the global default Python runtime instead of the specified one.
2. Custom executables (like `python_uv_test.exe`) were intercepted by the fallback wildcard search, resulting in arbitrary slicing and lookup errors for phantom version tags (e.g., `_uv_test`).

This commit introduces an `is_name_only` check (validating the absence of directory separators `/` and `\`) to safely distinguish bare commands from explicit paths. Gating the `is_default`, virtual alias, and wildcard extraction logic behind this check ensures explicit paths correctly fall through to `_find_on_path()`.
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.

PurePath.match() incorrectly intercepts and breaks absolute shebangs

1 participant