Fix path/branch extraction removing every /blob/ and /tree/ marker, not just the leading one#149
Open
patchwright wants to merge 1 commit into
Open
Conversation
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.
5f7183e to
8d9dcb9
Compare
Member
|
@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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/