mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-14 17:07:31 +00:00
fix(giturl): encode % (#2982)
This commit is contained in:
parent
ccf78494ee
commit
1f22522e86
2 changed files with 9 additions and 0 deletions
|
@ -174,6 +174,7 @@ var linePattern = regexp.MustCompile(`L\d+`)
|
||||||
// UpdateLinkLineNumber updates the line number in a repository link.
|
// UpdateLinkLineNumber updates the line number in a repository link.
|
||||||
// Used post-link generation to refine reported issue locations within large scanned blocks.
|
// Used post-link generation to refine reported issue locations within large scanned blocks.
|
||||||
func UpdateLinkLineNumber(ctx context.Context, link string, newLine int64) string {
|
func UpdateLinkLineNumber(ctx context.Context, link string, newLine int64) string {
|
||||||
|
link = strings.Replace(link, "%", "%25", -1)
|
||||||
parsedURL, err := url.Parse(link)
|
parsedURL, err := url.Parse(link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Logger().Error(err, "unable to parse link to update line number", "link", link)
|
ctx.Logger().Error(err, "unable to parse link to update line number", "link", link)
|
||||||
|
|
|
@ -289,6 +289,14 @@ func TestUpdateLinkLineNumber(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: "https://github.com/coinbase/cbpay-js/issues/181",
|
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",
|
name: "Invalid link",
|
||||||
args: args{
|
args: args{
|
||||||
|
|
Loading…
Reference in a new issue