Skip to content

fix(direct_url): parse URL scheme case-insensitively when checking for file URLs - #1240

Merged
henryiii merged 1 commit into
pypa:mainfrom
henryiii:fix/direct-url-file-scheme
Jun 24, 2026
Merged

henryiii merged 1 commit into
pypa:mainfrom
henryiii:fix/direct-url-file-scheme

Conversation

@henryiii

@henryiii henryiii commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Looks correct to me.

ðŸĪ– AI text below ðŸĪ–

Part of #1239

Summary

  • The check not direct_url.url.startswith("file://") in DirectUrl._from_dict() incorrectly rejected valid file URLs whose scheme used different casing (e.g. FILE:///path, File:///path), violating RFC 3986 §3.1 which states URI schemes are case-insensitive.
  • The same prefix test also rejected the RFC 8089 minimal form file:/path (single slash, no authority), which is a conformant file URL.
  • Fix: replace the prefix test with urllib.parse.urlsplit(url).scheme != "file". urlsplit already normalises the scheme to lowercase, so a single comparison handles all valid forms while still rejecting non-file schemes.
  • Regression tests added for FILE://, File://, and file:/ variants, plus confirmation that a non-file scheme (https://) still fails.

Test plan

  • uv run python -m pytest tests/test_direct_url.py -q — all 40 tests pass
  • prek -a --quiet — no lint or type errors

ðŸĪ– Generated with Claude Code

â€Ķr file URLs

Per RFC 3986 §3.1, URI schemes are case-insensitive, so FILE:// and
File:// are valid file URLs and must be accepted when dir_info is present.
The previous startswith("file://") check also incorrectly rejected the
RFC 8089 minimal form file:/path (single slash, no authority component).
Replace the prefix test with urllib.parse.urlsplit().scheme, which
already normalises the scheme to lowercase, covering both issues.

Assisted-by: ClaudeCode:claude-sonnet-4-6

@sbidoul sbidoul 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.

Looks good to me.

@henryiii
henryiii merged commit e80f70f into pypa:main Jun 24, 2026
59 checks passed
@henryiii
henryiii deleted the fix/direct-url-file-scheme branch June 24, 2026 11:58
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.

2 participants