diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 36b0abd16d7..8fe951d6d76 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix a bug where the "View Query Log" action for a query history item was not working. [#2984](https://github.com/github/vscode-codeql/pull/2984) - Add a command to sort items in the databases view by language. [#2993](https://github.com/github/vscode-codeql/pull/2993) - Fix not being able to open the results directory or evaluator log for a cancelled local query run. [#2996](https://github.com/github/vscode-codeql/pull/2996) +- Fix empty row in alert path when the SARIF location was empty. [#3018](https://github.com/github/vscode-codeql/pull/3018) ## 1.9.2 - 12 October 2023 diff --git a/extensions/ql-vscode/src/common/sarif-utils.ts b/extensions/ql-vscode/src/common/sarif-utils.ts index f30008c874b..fa9fc37b53a 100644 --- a/extensions/ql-vscode/src/common/sarif-utils.ts +++ b/extensions/ql-vscode/src/common/sarif-utils.ts @@ -1,6 +1,7 @@ import * as Sarif from "sarif"; import type { HighlightedRegion } from "../variant-analysis/shared/analysis-result"; import { ResolvableLocationValue } from "../common/bqrs-cli-types"; +import { isEmptyPath } from "./bqrs-utils"; export interface SarifLink { dest: number; @@ -111,6 +112,9 @@ export function parseSarifLocation( return { hint: "no artifact location" }; if (physicalLocation.artifactLocation.uri === undefined) return { hint: "artifact location has no uri" }; + if (isEmptyPath(physicalLocation.artifactLocation.uri)) { + return { hint: "artifact location has empty uri" }; + } // This is not necessarily really an absolute uri; it could either be a // file uri or a relative uri. diff --git a/extensions/ql-vscode/src/stories/results/AlertTable.stories.tsx b/extensions/ql-vscode/src/stories/results/AlertTable.stories.tsx index 4a559597b58..2d64154a8ed 100644 --- a/extensions/ql-vscode/src/stories/results/AlertTable.stories.tsx +++ b/extensions/ql-vscode/src/stories/results/AlertTable.stories.tsx @@ -389,6 +389,22 @@ WithCodeFlows.args = { message: { text: "id : String" }, }, }, + { + location: { + physicalLocation: { + artifactLocation: { + uri: "file:/", + index: 5, + }, + region: { + startLine: 13, + startColumn: 25, + endColumn: 54, + }, + }, + message: { text: "id : String" }, + }, + }, { location: { physicalLocation: { diff --git a/extensions/ql-vscode/test/unit-tests/common/sarif-utils.test.ts b/extensions/ql-vscode/test/unit-tests/common/sarif-utils.test.ts index 82ac859cfa5..968446811b9 100644 --- a/extensions/ql-vscode/test/unit-tests/common/sarif-utils.test.ts +++ b/extensions/ql-vscode/test/unit-tests/common/sarif-utils.test.ts @@ -76,6 +76,36 @@ describe("parsing sarif", () => { ).toEqual({ hint: "artifact location has no uri", }); + expect( + parseSarifLocation( + { + physicalLocation: { + artifactLocation: { + uri: "", + index: 5, + }, + }, + }, + "", + ), + ).toEqual({ + hint: "artifact location has empty uri", + }); + expect( + parseSarifLocation( + { + physicalLocation: { + artifactLocation: { + uri: "file:/", + index: 5, + }, + }, + }, + "", + ), + ).toEqual({ + hint: "artifact location has empty uri", + }); }); it("should parse a sarif location with no region and no file protocol", () => {