fix(giturl): encode % (#2982)

This commit is contained in:
Richard Gomez 2024-11-12 17:37:41 -05:00 committed by GitHub
parent ccf78494ee
commit 1f22522e86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -174,6 +174,7 @@ var linePattern = regexp.MustCompile(`L\d+`)
// UpdateLinkLineNumber updates the line number in a repository link.
// Used post-link generation to refine reported issue locations within large scanned blocks.
func UpdateLinkLineNumber(ctx context.Context, link string, newLine int64) string {
link = strings.Replace(link, "%", "%25", -1)
parsedURL, err := url.Parse(link)
if err != nil {
ctx.Logger().Error(err, "unable to parse link to update line number", "link", link)

View file

@ -289,6 +289,14 @@ func TestUpdateLinkLineNumber(t *testing.T) {
},
want: "https://github.com/coinbase/cbpay-js/issues/181",
},
{
name: "Encode percent",
args: args{
link: "https://github.com/coinbase/cbpay-js/blob/abcdefg/folder/%/name",
newLine: int64(0),
},
want: "https://github.com/coinbase/cbpay-js/blob/abcdefg/folder/%25/name",
},
{
name: "Invalid link",
args: args{