-
Couldn't load subscription status.
- Fork 1.1k
fix: URL-encode branch names in git provider links #2041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Branch names with special characters like '#' caused broken URLs because they weren't encoded correctly. This often happens when branch names come from GitLab issues (e.g., 'project#456'), since the hash symbol is mistakenly seen as a URL fragment. This change uses `urllib.parse.quote()` to encode the branch name component when generating links. This ensures special characters are correctly handled (e.g., '#test' becomes '%23test'), making the URLs robust. The fix has been applied to the link generation logic for the following providers: - GitLab - GitHub - Gitea - Bitbucket - Bitbucket Server
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
User description
Branch names with special characters like '#' caused broken URLs because they weren't encoded correctly. This often happens when branch names come from GitLab issues (e.g., 'project#456'), since the hash symbol is mistakenly seen as a URL fragment.
This change uses
urllib.parse.quote()to encode the branch name component when generating links. This ensures special characters are correctly handled (e.g., '#test' becomes '%23test'), making the URLs robust.The fix has been applied to the link generation logic for the following providers:
PR Type
Bug fix
Description
URL-encode branch names in git provider links
Fix broken URLs with special characters like '#'
Apply fix across GitLab, GitHub, Gitea, Bitbucket providers
Use
urllib.parse.quote()for proper encodingDiagram Walkthrough
File Walkthrough
bitbucket_provider.py
Add URL encoding for Bitbucket branch namespr_agent/git_providers/bitbucket_provider.py
quotefrom urllib.parseget_canonical_url_parts()bitbucket_server_provider.py
Add URL encoding for Bitbucket Server branch namespr_agent/git_providers/bitbucket_server_provider.py
quotefrom urllib.parsegitea_provider.py
Add URL encoding for Gitea branch namespr_agent/git_providers/gitea_provider.py
quotefrom urllib.parseget_line_link()methodgithub_provider.py
Add URL encoding for GitHub branch namespr_agent/git_providers/github_provider.py
quotefrom urllib.parseget_canonical_url_parts()gitlab_provider.py
Add URL encoding for GitLab branch namespr_agent/git_providers/gitlab_provider.py
quotefrom urllib.parseget_canonical_url_parts()get_line_link()andgenerate_link_to_relevant_line_number()