Skip to content

Fix PurePath.match intercepting absolute shebang paths - #349

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

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

Conversation

@mcexit

@mcexit mcexit commented May 24, 2026

Copy link
Copy Markdown

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()`.

@zooba zooba left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion is on the issue - changes will be required here once we establish what needs to be changed.

@zooba

zooba commented Jun 22, 2026

Copy link
Copy Markdown
Member

This has been fixed in an alternative way (see #359)

@zooba zooba closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants