Skip to content

Commit 6622d5e

Browse files
committed
Fix empty message with empty SARIF path
1 parent 3f83027 commit 6622d5e

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

extensions/ql-vscode/src/common/sarif-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Sarif from "sarif";
22
import type { HighlightedRegion } from "../variant-analysis/shared/analysis-result";
33
import { ResolvableLocationValue } from "../common/bqrs-cli-types";
4+
import { isEmptyPath } from "./bqrs-utils";
45

56
export interface SarifLink {
67
dest: number;
@@ -111,6 +112,9 @@ export function parseSarifLocation(
111112
return { hint: "no artifact location" };
112113
if (physicalLocation.artifactLocation.uri === undefined)
113114
return { hint: "artifact location has no uri" };
115+
if (isEmptyPath(physicalLocation.artifactLocation.uri)) {
116+
return { hint: "artifact location has empty uri" };
117+
}
114118

115119
// This is not necessarily really an absolute uri; it could either be a
116120
// file uri or a relative uri.

extensions/ql-vscode/src/stories/results/AlertTable.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,22 @@ WithCodeFlows.args = {
389389
message: { text: "id : String" },
390390
},
391391
},
392+
{
393+
location: {
394+
physicalLocation: {
395+
artifactLocation: {
396+
uri: "file:/",
397+
index: 5,
398+
},
399+
region: {
400+
startLine: 13,
401+
startColumn: 25,
402+
endColumn: 54,
403+
},
404+
},
405+
message: { text: "id : String" },
406+
},
407+
},
392408
{
393409
location: {
394410
physicalLocation: {

extensions/ql-vscode/test/unit-tests/common/sarif-utils.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,36 @@ describe("parsing sarif", () => {
7676
).toEqual({
7777
hint: "artifact location has no uri",
7878
});
79+
expect(
80+
parseSarifLocation(
81+
{
82+
physicalLocation: {
83+
artifactLocation: {
84+
uri: "",
85+
index: 5,
86+
},
87+
},
88+
},
89+
"",
90+
),
91+
).toEqual({
92+
hint: "artifact location has empty uri",
93+
});
94+
expect(
95+
parseSarifLocation(
96+
{
97+
physicalLocation: {
98+
artifactLocation: {
99+
uri: "file:/",
100+
index: 5,
101+
},
102+
},
103+
},
104+
"",
105+
),
106+
).toEqual({
107+
hint: "artifact location has empty uri",
108+
});
79109
});
80110

81111
it("should parse a sarif location with no region and no file protocol", () => {

0 commit comments

Comments
 (0)