Skip to content

Commit 59a9070

Browse files
authored
fix: Handle percent-encoded characters in wheel file URLs (#248)
Fixes issue #247.
1 parent bf15f51 commit 59a9070

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

micropip/wheelinfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dataclasses import dataclass, field
66
from pathlib import Path
77
from typing import Any, Literal
8-
from urllib.parse import ParseResult, urlparse
8+
from urllib.parse import ParseResult, unquote, urlparse
99

1010
from ._compat import (
1111
fetch_bytes,
@@ -78,7 +78,7 @@ def from_url(cls, url: str) -> "WheelInfo":
7878
query=parsed_url.query,
7979
fragment=parsed_url.fragment,
8080
)
81-
file_name = Path(parsed_url.path).name
81+
file_name = Path(unquote(parsed_url.path)).name
8282
name, version, build, tags = parse_wheel_filename(file_name)
8383
return WheelInfo(
8484
name=name,

tests/test_wheelinfo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ def test_from_url():
1515
assert wheel.sha256 is None
1616

1717

18+
def test_from_url_with_percent_encoded_path():
19+
# Test URL with percent-encoded characters (+ encoded as %2B in version string)
20+
url = "https://test.com/dummy_module-1.0.0%2Blocalbuild.1-py3-none-any.whl"
21+
wheel = WheelInfo.from_url(url)
22+
23+
assert wheel.name == "dummy-module"
24+
assert str(wheel.version) == "1.0.0+localbuild.1"
25+
assert wheel.url == url
26+
assert wheel.filename == "dummy_module-1.0.0+localbuild.1-py3-none-any.whl"
27+
assert wheel.size is None
28+
assert wheel.sha256 is None
29+
30+
1831
def test_from_package_index():
1932
name = "dummy-module"
2033
filename = "dummy_module-0.0.1-py3-none-any.whl"

0 commit comments

Comments
 (0)