Skip to content

Commit d130132

Browse files
claudespoorcc
authored andcommitted
Fix trailing slash in URL causing ValueError in add command (issue #1137)
Strip trailing slashes from VCS URLs at the entry point of vcs_url_to_purl so that patterns like https://github.com/org/repo/ are normalised before regex matching and path splitting. Add parametrized regression tests for GitHub, Bitbucket, GitLab, and generic URLs with trailing slashes. https://claude.ai/code/session_01HousmFCGC1BbEczgkmTSC6
1 parent a4a27c6 commit d130132

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

dfetch/util/purl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def vcs_url_to_purl(
114114
Supports GitHub, Bitbucket, SVN, SSH paths, and generic VCS URLs.
115115
Optionally specify version and subpath.
116116
"""
117+
vcs_url = vcs_url.rstrip("/")
117118
purl = _known_purl_types(vcs_url, version, subpath)
118119
if purl:
119120
return purl

tests/test_purl.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@
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+
# Trailing slash – issue #1137
119+
("https://github.com/cpputest/cpputest/", "pkg:github/cpputest/cpputest"),
120+
("https://github.com/dfetch-org/dfetch/", "pkg:github/dfetch-org/dfetch"),
121+
("https://bitbucket.org/team/repo/", "pkg:bitbucket/team/repo"),
122+
(
123+
"https://gitlab.com/group/project/",
124+
"pkg:generic/group/project?vcs_url=https://gitlab.com/group/project",
125+
),
126+
(
127+
"https://vcs.example.com/org/repo/",
128+
"pkg:generic/example/org/repo?vcs_url=https://vcs.example.com/org/repo",
129+
),
118130
],
119131
)
120132
def test_remote_url_to_purl(url, expected):

0 commit comments

Comments
 (0)