Skip to content

Preserve literal percent escapes when opening local file URLs - #6791

Merged
matteius merged 3 commits into
pypa:mainfrom
anishpentyala:fix/file-url-single-decode
Nov 18, 2026
Merged

matteius merged 3 commits into
pypa:mainfrom
anishpentyala:fix/file-url-single-decode

Conversation

@anishpentyala

Copy link
Copy Markdown
Contributor

The issue

Fixes #6790.

url_to_path calls url2pathname, which already decodes percent escapes. Calling unquote again changes literal sequences in filenames, such as requirements%20dev.txt into requirements dev.txt, so open_file cannot find the original file.

The fix

Remove the second decode and keep platform-specific conversion in url2pathname. Add 15 tests for path/URL round trips, actual local file opening, spaces/plus/Unicode controls and the Path return type. Only project-owned code is changed; vendor/ and patched/ are untouched.

Validation on Linux with CPython 3.13.18 and 3.14.10:

  • Focused and existing utility tests: 240 passed and 7 skipped on each.
  • Full unit suite: 1,970 passed, 11 skipped and 1 failure on each. The same failure occurs on unchanged base (1,955 passed, 11 skipped and 1 failure): tests/unit/test_manifest_cache.py::TestCorruptionRobustness::test_expires_at_wrong_type_treated_as_miss. It returns the in-memory cached manifest after the test changes the on-disk expires_at type. This patch does not change that code. The full unit suite is not all green.
  • Reverting only the runtime fix fails 11 new cases; the other 4 cases also pass on baseline.
  • A separate seeded 5,000-filename oracle passes 10,000 URL round trips.
  • Changed-file Ruff 0.9.3 and Black 26.10.1 checks pass, as does git diff --check.

No Windows/macOS, integration suite, private package-index server, full-install/CLI resolver or remote CI result is claimed. No broad coverage-threshold pass is claimed.

The checklist

  • Associated issue
  • A numbered bugfix news fragment: news/6790.bugfix.rst

Remove URL decoding from path string before returning.
Add unit tests for file URL path conversions and file opening.
Preserve literal percent escapes in local file paths when converting file URLs.
@matteius
matteius merged commit 31a6aba into pypa:main Nov 18, 2026
25 of 26 checks passed
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.

Local file URLs are decoded twice, breaking filenames with literal percent escapes

2 participants