Skip to content

Commit db1ac11

Browse files
committed
Fix purl namespace corruption when path contains ".git" mid-path
The generic VCS branch in _vcs_namespace_and_name used str.replace to strip a ".git" suffix from the path, which silently removed every occurrence anywhere in the path. A URL like https://gitlab.com/group/foo.github/project.git produced the namespace "group/foohub" instead of "group/foo.github". Use removesuffix so only the trailing .git is stripped. https://claude.ai/code/session_01KKvrvnVvsBChohuxbRRmzA
1 parent e35c251 commit db1ac11

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Release 0.14.1 (unreleased)
2+
===========================
3+
4+
* Fix ``dfetch import`` mangling the namespace of a generic VCS URL whose path contains ``.git`` other than as a suffix
5+
16
Release 0.14.0 (released 2026-06-14)
27
===========================
38

dfetch/util/purl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _vcs_namespace_and_name(remote_url: str) -> tuple[str, str, str]:
101101
remote_url = f"ssh://{parsed.path.replace(':', '/')}"
102102
else:
103103
namespace, name = _namespace_and_name_from_domain_and_path(
104-
remote_url, path.replace(".git", "")
104+
remote_url, path.removesuffix(".git")
105105
)
106106
return namespace, name, remote_url
107107

tests/test_purl.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@
115115
"git://git.git.savannah.gnu.org/automake.git",
116116
"pkg:generic/automake?vcs_url=git://git.git.savannah.gnu.org/automake.git",
117117
),
118+
# A ".git" substring inside the path must not be stripped (only the suffix)
119+
(
120+
"https://gitlab.com/group/foo.github/project.git",
121+
"pkg:generic/group/foo.github/project?vcs_url=https://gitlab.com/group/foo.github/project.git",
122+
),
118123
# Trailing slash – issue #1137
119124
("https://github.com/cpputest/cpputest/", "pkg:github/cpputest/cpputest"),
120125
("https://github.com/dfetch-org/dfetch/", "pkg:github/dfetch-org/dfetch"),

0 commit comments

Comments
 (0)