Skip to content

Commit 190f454

Browse files
addition of percent encoding for raw brackets CSM-1195 (#4221)
* straightforward addition of percent encoding for raw brackets * added test case for bracket encoding
1 parent f649faa commit 190f454

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pkg/giturl/giturl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ func GenerateLink(repo, commit, file string, line int64) string {
121121
// Some paths contain '%' which breaks |url.Parse| if not encoded.
122122
// https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding
123123
file = strings.ReplaceAll(file, "%", "%25")
124+
file = strings.ReplaceAll(file, "[", "%5B")
125+
file = strings.ReplaceAll(file, "]", "%5D")
124126

125127
switch determineProvider(repo) {
126128
case providerBitbucket:
@@ -175,6 +177,8 @@ var linePattern = regexp.MustCompile(`L\d+`)
175177
// Used post-link generation to refine reported issue locations within large scanned blocks.
176178
func UpdateLinkLineNumber(ctx context.Context, link string, newLine int64) string {
177179
link = strings.Replace(link, "%", "%25", -1)
180+
link = strings.Replace(link, "[", "%5B", -1)
181+
link = strings.Replace(link, "]", "%5D", -1)
178182
parsedURL, err := url.Parse(link)
179183
if err != nil {
180184
ctx.Logger().Error(err, "unable to parse link to update line number", "link", link)

pkg/giturl/giturl_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ func TestUpdateLinkLineNumber(t *testing.T) {
305305
},
306306
wantErr: true,
307307
},
308+
{
309+
name: "Encode brackets",
310+
args: args{
311+
link: "https://github.com/coinbase/cbpay-js/blob/abcdefg/folder/[name]/file",
312+
newLine: int64(0),
313+
},
314+
want: "https://github.com/coinbase/cbpay-js/blob/abcdefg/folder/%5Bname%5D/file",
315+
},
308316
}
309317

310318
for _, tt := range tests {

0 commit comments

Comments
 (0)