Skip to content

Commit

Permalink
Merge pull request #3018 from github/koesie10/fix-empty-location
Browse files Browse the repository at this point in the history
Fix empty message with empty SARIF path
  • Loading branch information
koesie10 authored Oct 26, 2023
2 parents 9a97b7b + 06b6595 commit 40a77df
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions extensions/ql-vscode/src/common/sarif-utils.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions extensions/ql-vscode/src/stories/results/AlertTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
30 changes: 30 additions & 0 deletions extensions/ql-vscode/test/unit-tests/common/sarif-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 40a77df

Please sign in to comment.