Skip to content

Commit

Permalink
fix: encode urls for go
Browse files Browse the repository at this point in the history
trusty api expects to receive the url in an encoded format

Closes: #2
  • Loading branch information
yrobla committed Apr 24, 2024
1 parent f516a17 commit 3b6a470
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/parser/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package parser

import (
"net/url"
"strings"

"github.com/stacklok/trusty-action/pkg/types"
Expand Down Expand Up @@ -52,10 +53,14 @@ func ParseGoMod(content string) ([]types.Dependency, error) {
depName = parts[0]
depVersion = parts[1]
} else { // Inline require
if len(parts) < 3 {
continue // Skip malformed inline requires that do not have both a name and a version
}
depName = parts[1]
depVersion = parts[2]
}
deps = append(deps, types.Dependency{Name: depName, Version: depVersion})
encodedDepName := url.PathEscape(depName)
deps = append(deps, types.Dependency{Name: encodedDepName, Version: depVersion})
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestParse(t *testing.T) {
filename: "go.mod",
content: "module example.com\n\ngo 1.16\n\nrequire (\n\tgithub.com/google/go-github/v60 v60.0.0\n)",
expected: []types.Dependency{
{Name: "github.com/google/go-github/v60", Version: "v60.0.0"},
{Name: "github.com%2Fgoogle%2Fgo-github%2Fv60", Version: "v60.0.0"},
},
ecosystem: "go",
err: nil,
Expand Down

0 comments on commit 3b6a470

Please sign in to comment.