fix(giturl): encode '%' in path (#2214)

This commit is contained in:
Richard Gomez
2023-12-14 11:06:09 -05:00
committed by GitHub
parent f38b6a27b6
commit 22ae6a7a8f
2 changed files with 14 additions and 0 deletions
+4
View File
@@ -118,6 +118,10 @@ func NormalizeOrgRepoURL(provider provider, repoURL string) (string, error) {
// Supports GitHub, GitLab, Bitbucket, and Azure Repos.
// If the provider supports hyperlinks to specific lines, the line number will be included.
func GenerateLink(repo, commit, file string, line int64) string {
// Some paths contain '%' which breaks |url.Parse| if not encoded.
// https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding
file = strings.Replace(file, "%", "%25", -1)
switch determineProvider(repo) {
case providerBitbucket:
return repo[:len(repo)-4] + "/commits/" + commit
+10
View File
@@ -200,6 +200,16 @@ func TestGenerateLink(t *testing.T) {
},
want: "https://gist.github.com/joeleonjr/be68e34b002e236160dbb394bbda86fb/c64bf2345256cca7d2621f9cb78401e8860f82c8/#file-test-txt-ps1-L4",
},
{
name: "link gen - file percent in path",
args: args{
repo: "https://github.com/GeekMasher/tree-sitter-hcl.git",
commit: "a7f23cc5795769262f5515e52902f86c1b768994",
file: "example/real_world_stuff/coreos/coreos%tectonic-installer%installer%frontend%ui-tests%output%metal.tfvars",
line: int64(1),
},
want: "https://github.com/GeekMasher/tree-sitter-hcl/blob/a7f23cc5795769262f5515e52902f86c1b768994/example/real_world_stuff/coreos/coreos%25tectonic-installer%25installer%25frontend%25ui-tests%25output%25metal.tfvars#L1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {