Fix path/branch extraction removing every /blob/ and /tree/ marker, not just the leading one#149
Conversation
5f7183e to
8d9dcb9
Compare
|
@patchwright Hi! Thanks for pointing this out. In order to merge this (and to make the CI pass), I've created #150 this issue. Would you be so kind to:
|
GitHubPlatform and GitLabPlatform built `path`/`branch` with
str.replace(marker, ""), which removes *every* occurrence of the
marker rather than only the leading one. A URL whose file path or
branch name contained the same segment again was silently corrupted:
parse('.../blob/main/src/blob/utils.py').path -> 'main/srcutils.py'
parse('.../tree/feature/tree/x').branch -> 'featurex'
The leading marker is already guaranteed by the preceding startswith
check, so slice it off instead. Slicing (rather than str.removeprefix)
keeps the declared Python 3.8 compatibility. Adds regression tests for
nested /blob/ paths and /tree/ branch names on both GitHub and GitLab.
8d9dcb9 to
24b4612
Compare
|
@protoroto Renamed the fragment to On the branch rename: renaming the head branch of a fork-sourced PR closes the PR, so I kept the original branch name to leave this open and mergeable. The branch name doesn't affect the checks; if you'd still like it renamed I can push under the new name and reopen a fresh PR — happy to do that. |
|
@patchwright Hi! Thanks for your quick response! Sadly,
so if you would be so kind to re-open this pr with the new branch name, I'll be more than happy to merge and release it as soon as possible! Thanks again! |
|
@protoroto Done — re-opened as #152 from branch |
Description
pathandbranchare extracted from the matched URL by removing the leading/blob/,/tree/,/-/blob/or/-/tree/marker. The code did this withstr.replace(marker, ""), which removes every occurrence of the marker, notjust the leading one. When the file path or branch name legitimately contains the
same segment again, the result is silently corrupted.
For example:
The leading marker is already guaranteed by the preceding
startswith(...)check,so the fix is to slice off exactly that prefix instead of calling
replace:Slicing is used (rather than
str.removeprefix) to remain compatible with thedeclared
python_requires = >=3.8.Fixed in both the GitHub and GitLab platforms.
References
No existing issue.
Checklist
inv lint(ruff, black, isort all clean on the changed files)/blob/paths and/tree/branch names on both GitHub and GitLab; verified to fail on the previous code and pass with the fix)changes/