Skip to content

Commit

Permalink
fix(WindowsApplicationIconExtractor): ignore case of file extension (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener authored Oct 3, 2024
1 parent 8d183c6 commit 02356e1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";
import { WindowsApplicationIconExtractor } from "./WindowsApplicationIconExtractor";

describe(WindowsApplicationIconExtractor, () => {
describe(WindowsApplicationIconExtractor.prototype.matchesFilePath, () => {
const testMatchesFilePath = ({ filePath, expected }: { filePath: string; expected: boolean }) =>
expect(new WindowsApplicationIconExtractor(null, null, null, "").matchesFilePath(filePath)).toBe(expected);

it("should return true when file path ends with .lnk, .url, .appref-ms, .exe", () => {
const filePaths = [
"file.lnk",
"file.url",
"file.appref-ms",
"file.exe",
"file.LNK",
"file.URL",
"file.APPREF-MS",
"file.EXE",
];

for (const filePath of filePaths) {
testMatchesFilePath({ filePath, expected: true });
}
});

it("should return false when file path ends with other file extensions", () => {
const filePaths = [
"",
" ",
"file",
"file.ln",
"file.ex",
"lnk",
"exe",
"file.txt",
"file.doc",
"file.docx",
"file.pdf",
"file.jpg",
"file.png",
];

for (const filePath of filePaths) {
testMatchesFilePath({ filePath, expected: false });
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ export class WindowsApplicationIconExtractor implements FileIconExtractor {
) {}

public matchesFilePath(filePath: string) {
return (
filePath.endsWith(".lnk") ||
filePath.endsWith(".url") ||
filePath.endsWith(".appref-ms") ||
filePath.endsWith(".exe")
return [".lnk", ".url", ".appref-ms", ".exe"].some((fileExtension) =>
filePath.toLowerCase().endsWith(fileExtension),
);
}

Expand Down

0 comments on commit 02356e1

Please sign in to comment.