Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct path separator in SARIF output when on Windows #1294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
PathSeparator 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""
""{{.}}{{$.PathSeparator}}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,
PathSeparator: 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
22 changes: 11 additions & 11 deletions internal/output/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func TestPrintSARIFReport(t *testing.T) {
map[string]string{
"lockfile:D:\\\\path\\\\to\\\\sub-rust-project\\\\Cargo.lock": "lockfile:/path/to/sub-rust-project/Cargo.lock",
"lockfile:D:\\\\path\\\\to\\\\go.mod": "lockfile:/path/to/go.mod",
"D:\\\\path\\\\to\\\\sub-rust-project/osv-scanner.toml": "/path/to/sub-rust-project/osv-scanner.toml",
"D:\\\\path\\\\to/osv-scanner.toml": "/path/to/osv-scanner.toml",
"D:\\\\path\\\\to\\\\sub-rust-project\\\\osv-scanner.toml": "/path/to/sub-rust-project/osv-scanner.toml",
"D:\\\\path\\\\to\\\\osv-scanner.toml": "/path/to/osv-scanner.toml",
"file:///D:/path/to": "file:///path/to",
},
),
Expand Down Expand Up @@ -100,9 +100,9 @@ func TestPrintSARIFReport_WithVulnerabilities(t *testing.T) {

testutility.NewSnapshot().WithWindowsReplacements(
map[string]string{
"path\\\\to\\\\my\\\\first/osv-scanner.toml": "path/to/my/first/osv-scanner.toml",
"path\\\\to\\\\my\\\\second/osv-scanner.toml": "path/to/my/second/osv-scanner.toml",
"path\\\\to\\\\my\\\\third/osv-scanner.toml": "path/to/my/third/osv-scanner.toml",
"path\\\\to\\\\my\\\\first\\\\osv-scanner.toml": "path/to/my/first/osv-scanner.toml",
"path\\\\to\\\\my\\\\second\\\\osv-scanner.toml": "path/to/my/second/osv-scanner.toml",
"path\\\\to\\\\my\\\\third\\\\osv-scanner.toml": "path/to/my/third/osv-scanner.toml",
}).MatchText(t, outputWriter.String())
})
}
Expand All @@ -122,9 +122,9 @@ func TestPrintSARIFReport_WithLicenseViolations(t *testing.T) {

testutility.NewSnapshot().WithWindowsReplacements(
map[string]string{
"path\\\\to\\\\my\\\\first/osv-scanner.toml": "path/to/my/first/osv-scanner.toml",
"path\\\\to\\\\my\\\\second/osv-scanner.toml": "path/to/my/second/osv-scanner.toml",
"path\\\\to\\\\my\\\\third/osv-scanner.toml": "path/to/my/third/osv-scanner.toml",
"path\\\\to\\\\my\\\\first\\\\osv-scanner.toml": "path/to/my/first/osv-scanner.toml",
"path\\\\to\\\\my\\\\second\\\\osv-scanner.toml": "path/to/my/second/osv-scanner.toml",
"path\\\\to\\\\my\\\\third\\\\osv-scanner.toml": "path/to/my/third/osv-scanner.toml",
}).MatchText(t, outputWriter.String())
})
}
Expand All @@ -144,9 +144,9 @@ func TestPrintSARIFReport_WithMixedIssues(t *testing.T) {

testutility.NewSnapshot().WithWindowsReplacements(
map[string]string{
"path\\\\to\\\\my\\\\first/osv-scanner.toml": "path/to/my/first/osv-scanner.toml",
"path\\\\to\\\\my\\\\second/osv-scanner.toml": "path/to/my/second/osv-scanner.toml",
"path\\\\to\\\\my\\\\third/osv-scanner.toml": "path/to/my/third/osv-scanner.toml",
"path\\\\to\\\\my\\\\first\\\\osv-scanner.toml": "path/to/my/first/osv-scanner.toml",
"path\\\\to\\\\my\\\\second\\\\osv-scanner.toml": "path/to/my/second/osv-scanner.toml",
"path\\\\to\\\\my\\\\third\\\\osv-scanner.toml": "path/to/my/third/osv-scanner.toml",
}).MatchText(t, outputWriter.String())
})
}
Loading