Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/149.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``path`` and ``branch`` extraction removing *every* ``/blob/`` and ``/tree/`` occurrence instead of only the leading marker, which corrupted file paths and branch names containing those segments.
4 changes: 2 additions & 2 deletions giturlparse/platforms/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GitHubPlatform(BasePlatform):
def clean_data(data):
data = BasePlatform.clean_data(data)
if data["path_raw"].startswith("/blob/"):
data["path"] = data["path_raw"].replace("/blob/", "")
data["path"] = data["path_raw"][len("/blob/") :]
if data["path_raw"].startswith("/tree/"):
data["branch"] = data["path_raw"].replace("/tree/", "")
data["branch"] = data["path_raw"][len("/tree/") :]
return data
6 changes: 3 additions & 3 deletions giturlparse/platforms/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class GitLabPlatform(BasePlatform):
def clean_data(data):
data = BasePlatform.clean_data(data)
if data["path_raw"].startswith("/blob/"):
data["path"] = data["path_raw"].replace("/blob/", "")
data["path"] = data["path_raw"][len("/blob/") :]
if data["path_raw"].startswith("/-/blob/"):
data["path"] = data["path_raw"].replace("/-/blob/", "")
data["path"] = data["path_raw"][len("/-/blob/") :]
if data["path_raw"].startswith("/-/tree/"):
data["branch"] = data["path_raw"].replace("/-/tree/", "")
data["branch"] = data["path_raw"][len("/-/tree/") :]
return data
74 changes: 74 additions & 0 deletions giturlparse/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,80 @@
},
),
),
(
"HTTPS",
(
# Regression: a file path that itself contains a "blob" directory must
# not have the inner "/blob/" stripped (only the leading marker).
"https://github.com/nephila/giturlparse/blob/master/giturlparse/blob/data.py",
{
"host": "github.com",
"resource": "github.com",
"port": "",
"user": "git",
"owner": "nephila",
"repo": "giturlparse",
"name": "giturlparse",
"groups": [],
"path": "master/giturlparse/blob/data.py",
"path_raw": "/blob/master/giturlparse/blob/data.py",
"pathname": "/nephila/giturlparse/blob/master/giturlparse/blob/data.py",
"branch": "",
"protocol": "https",
"protocols": ["https"],
"platform": "github",
},
),
),
(
"HTTPS",
(
# Regression: a branch name containing "/tree/" must be preserved
# in full rather than having every "/tree/" removed.
"https://github.com/nephila/giturlparse/tree/feature/tree/x",
{
"host": "github.com",
"resource": "github.com",
"port": "",
"user": "git",
"owner": "nephila",
"repo": "giturlparse",
"name": "giturlparse",
"groups": [],
"path": "",
"path_raw": "/tree/feature/tree/x",
"pathname": "/nephila/giturlparse/tree/feature/tree/x",
"branch": "feature/tree/x",
"protocol": "https",
"protocols": ["https"],
"platform": "github",
},
),
),
(
"HTTPS",
(
# Regression (GitLab): inner "/blob/" in the file path must survive.
"https://gitlab.com/nephila/giturlparse/-/blob/master/giturlparse/blob/data.py",
{
"host": "gitlab.com",
"resource": "gitlab.com",
"port": "",
"user": "git",
"owner": "nephila",
"repo": "giturlparse",
"name": "giturlparse",
"groups": [],
"path": "master/giturlparse/blob/data.py",
"path_raw": "/-/blob/master/giturlparse/blob/data.py",
"pathname": "/nephila/giturlparse/-/blob/master/giturlparse/blob/data.py",
"branch": "",
"protocol": "https",
"protocols": ["https"],
"platform": "gitlab",
},
),
),
(
"HTTPS",
(
Expand Down
Loading