Skip to content

Commit

Permalink
fix: use correct path seperator in SARIF output when on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Oct 2, 2024
1 parent a20e520 commit c5f0be6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/output/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type HelpTemplateData struct {
AliasedVulns []VulnDescription
HasFixedVersion bool
FixedVersionTable string
PathSeperator string
}

type FixedPkgTableData struct {
Expand Down Expand Up @@ -81,7 +82,7 @@ See the format and more options in our documentation here: https://google.github
Add or append these values to the following config files to ignore this vulnerability:
{{range .AffectedPackagePaths -}}
""{{.}}/osv-scanner.toml""
""{{.}}{{$.PathSeperator}}osv-scanner.toml""
""""""
[[IgnoredVulns]]
Expand Down Expand Up @@ -213,6 +214,7 @@ func createSARIFHelpText(gv *groupedSARIFFinding) string {
HasFixedVersion: hasFixedVersion,
FixedVersionTable: createSARIFFixedPkgTable(fixedPkgTableData).RenderMarkdown(),
AffectedPackagePaths: affectedPackagePaths,
PathSeperator: string(filepath.Separator),
})

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/output/sarif_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func Test_createSARIFHelpText(t *testing.T) {
{
args: testutility.LoadJSONFixture[groupedSARIFFinding](t, "fixtures/vuln-grouped.json"),
want: testutility.NewSnapshot().WithWindowsReplacements(map[string]string{
"\\path\\to\\sub-rust-project/osv-scanner.toml": "/path/to/sub-rust-project/osv-scanner.toml",
"\\path\\to\\sub-rust-project\\osv-scanner.toml": "/path/to/sub-rust-project/osv-scanner.toml",
}),
},
{
args: testutility.LoadJSONFixture[groupedSARIFFinding](t, "fixtures/commit-grouped.json"),
want: testutility.NewSnapshot().WithWindowsReplacements(map[string]string{
"<rootdir>\\Documents\\Project\\engine/osv-scanner.toml": "<rootdir>/Documents/Project/engine/osv-scanner.toml",
"<rootdir>\\Documents\\Project\\engine\\osv-scanner.toml": "<rootdir>/Documents/Project/engine/osv-scanner.toml",
}),
},
}
Expand Down

0 comments on commit c5f0be6

Please sign in to comment.