Fix empty message with empty SARIF path

This commit is contained in:
Koen Vlaswinkel
2023-10-25 14:55:15 +02:00
parent 3f8302796f
commit 6622d5e114
3 changed files with 50 additions and 0 deletions

View File

@@ -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.

View File

@@ -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: {

View File

@@ -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", () => {