X Tutup
Skip to content

Commit 24ba354

Browse files
generateCompareURL uses url.PathEscape instead of url.QueryEscape
For ctx.{BaseBranch,HeadBranchLabel}.
1 parent 6fbe6d9 commit 24ba354

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pkg/cmd/pr/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ func generateCompareURL(ctx CreateContext, state shared.IssueMetadataState) (str
755755
u := ghrepo.GenerateRepoURL(
756756
ctx.BaseRepo,
757757
"compare/%s...%s?expand=1",
758-
url.QueryEscape(ctx.BaseBranch), url.QueryEscape(ctx.HeadBranchLabel))
758+
url.PathEscape(ctx.BaseBranch), url.PathEscape(ctx.HeadBranchLabel))
759759
url, err := shared.WithPrAndIssueQueryParams(ctx.Client, ctx.BaseRepo, u, state)
760760
if err != nil {
761761
return "", err

pkg/cmd/pr/create/create_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,29 @@ func Test_generateCompareURL(t *testing.T) {
989989
wantErr: false,
990990
},
991991
{
992-
name: "complex branch names",
992+
name: "'/'s in branch names/labels are percent-encoded",
993993
ctx: CreateContext{
994994
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
995995
BaseBranch: "main/trunk",
996996
HeadBranchLabel: "owner:feature",
997997
},
998-
want: "https://github.com/OWNER/REPO/compare/main%2Ftrunk...owner%3Afeature?body=&expand=1",
998+
want: "https://github.com/OWNER/REPO/compare/main%2Ftrunk...owner:feature?body=&expand=1",
999+
wantErr: false,
1000+
},
1001+
{
1002+
name: "Any of !'(),; but none of $&+=@ and : in branch names/labels are percent-encoded ",
1003+
/*
1004+
- Technically, per section 3.3 of RFC 3986, none of !$&'()*+,;= (sub-delims) and :[]@ (part of gen-delims) in path segments are optionally percent-encoded, but url.PathEscape percent-encodes !'(),; anyway
1005+
- !$&'()+,;=@ is a valid Git branch name—essentially RFC 3986 sub-delims without * and gen-delims without :/?#[]
1006+
- : is GitHub separator between a fork name and a branch name
1007+
- See https://github.com/golang/go/issues/27559.
1008+
*/
1009+
ctx: CreateContext{
1010+
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
1011+
BaseBranch: "main/trunk",
1012+
HeadBranchLabel: "owner:!$&'()+,;=@",
1013+
},
1014+
want: "https://github.com/OWNER/REPO/compare/main%2Ftrunk...owner:%21$&%27%28%29+%2C%3B=@?body=&expand=1",
9991015
wantErr: false,
10001016
},
10011017
}

0 commit comments

Comments
 (0)
X Tutup