diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts index 30dc6f4..c389ab6 100644 --- a/sdk/typescript/src/cli.ts +++ b/sdk/typescript/src/cli.ts @@ -2877,7 +2877,7 @@ function scanScope(arguments_: ScanArguments): string | null { isAbsolute(path) || /^[A-Za-z]:\//u.test(portable) || portable.startsWith("//") - ? portable.split("/").at(-1) ?? portable + ? basename(portable) || portable : portable; return redactedErrorMessage( scoped.replaceAll(/[\u0000-\u001F\u007F]/gu, " "), diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts index d16b6db..14afe94 100644 --- a/sdk/typescript/tests-ts/cli.test.ts +++ b/sdk/typescript/tests-ts/cli.test.ts @@ -2538,6 +2538,29 @@ describe("CLI", () => { expect(stderr.text()).not.toContain("% complete"); }); + test("preserves directory names for absolute scan paths with trailing separators", async () => { + const stdout = capture(); + const stderr = capture(); + + expect( + await main( + [ + "scan", + ".", + "--path", + "/synthetic-parent/trailing-directory/", + "--json", + ], + stdout.stream, + stderr.stream, + dependencies(), + ), + ).toBe(0); + expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON()); + expect(stderr.text()).toContain("Running scan: trailing-directory"); + expect(stderr.text()).not.toContain("synthetic-parent"); + }); + test("prints a truthful completion summary without changing JSON results", async () => { const stdout = capture(); const stderr = capture();