Skip to content

Commit 87894de

Browse files
Merge pull request #144 from packit/filename
Follow RPM logic exactly when extracting filename from URL Reviewed-by: Tomas Tomecek <[email protected]>
2 parents e844b03 + 06d6c06 commit 87894de

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

specfile/utils.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import re
99
import sys
1010
import tempfile
11-
import urllib.parse
12-
from pathlib import Path
1311
from typing import Iterator, List
1412

1513
from specfile.exceptions import SpecfileException
@@ -117,9 +115,7 @@ def get_filename_from_location(location: str) -> str:
117115
Returns:
118116
Extracted filename that can be empty if there is none.
119117
"""
120-
url = urllib.parse.urlsplit(location)
121-
if url.fragment:
122-
if "/" in url.fragment:
123-
return Path(url.fragment).name.split("=")[-1]
124-
return Path(f"{url.path}#{url.fragment}").name
125-
return Path(url.path).name
118+
slash = location.rfind("/")
119+
if slash < 0:
120+
return location
121+
return location[slash + 1 :].split("=")[-1]

tests/unit/test_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
[
1212
("", ""),
1313
("tarball-0.1.tar.gz", "tarball-0.1.tar.gz"),
14-
("https://example.com", ""),
14+
("https://example.com", "example.com"),
15+
("https://example.com#fragment", "example.com#fragment"),
1516
("https://example.com/archive/tarball-0.1.tar.gz", "tarball-0.1.tar.gz"),
1617
(
1718
"https://example.com/archive/tarball-0.1.tar.gz#fragment",

0 commit comments

Comments
 (0)