diff --git a/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.spec.ts b/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.spec.ts index b9346d7c1..c9b5c438c 100644 --- a/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.spec.ts +++ b/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.spec.ts @@ -28,6 +28,18 @@ describe("CommaSeperatedFileList", () => { expect(result).toBe("__test123__"); }); + test("should ignore/handle empty string translated for inputs without dots", () => { + // yes empty string is a non-valid option + const result = comma.CommaSpaceLastDot(["example.test", "another", "final.test"], ""); + expect(result).toBe(", test"); + }); + + test("should ignore/handle null translated for inputs without dots", () => { + // yes null is a non-valid option + const result = comma.CommaSpaceLastDot(["example.test", "another", "final.test"], null!); + expect(result).toBe("test, without extension"); + }); + test("should handle mixed inputs with and without dots", () => { const result = comma.CommaSpaceLastDot(["example.test", "another", "final.test"]); expect(result).toBe("test, without extension"); diff --git a/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.ts b/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.ts index 51676a84f..50d149236 100644 --- a/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.ts +++ b/starsky/starsky/clientapp/src/shared/comma-seperated-filelist/comma-seperated-filelist.ts @@ -14,12 +14,14 @@ export class CommaSeperatedFileList { private GetUniqueExtensions(inputs: string[], messageNoExtensionItem?: string): Array { const uniqueExtensions = new Set(); + const messageNoExtension = messageNoExtensionItem ?? "without extension"; + for (const element of inputs) { const fileExtension = element.split(".")[element.split(".").length - 1]; if (element !== fileExtension) { uniqueExtensions.add(fileExtension); } else { - uniqueExtensions.add(messageNoExtensionItem || "without extension"); + uniqueExtensions.add(messageNoExtension); } } return Array.from(uniqueExtensions).sort((a, b) =>