Skip to content

Build your personal knowledge base with Trilium Notes

fix(commons): refuse a reserved Windows name whatever the extension

sxh488c0f8c2077
diff --git a/packages/commons/src/lib/filesystem_name.spec.ts b/packages/commons/src/lib/filesystem_name.spec.ts
index 0821786798..5fd1246b0c 100644
--- a/packages/commons/src/lib/filesystem_name.spec.ts
+++ b/packages/commons/src/lib/filesystem_name.spec.ts
@@ -65,8 +65,13 @@ describe("asFileName", () => {
expect(asFileName("NUL")).toBeNull();
expect(asFileName("com1")).toBeNull();
expect(asFileName("Aux")).toBeNull();
+ expect(asFileName("NUL.txt")).toBeNull();
+ expect(asFileName("COM1.xls")).toBeNull();
+ expect(asFileName("aux.tar.gz")).toBeNull();
// Only the names themselves, not everything starting with them.
expect(asFileName("nullify")).toBe("nullify");
+ expect(asFileName("nullify.txt")).toBe("nullify.txt");
+ expect(asFileName("confidence.csv")).toBe("confidence.csv");
});
it("never answers with something that reaches outside the directory it is used in", () => {
diff --git a/packages/commons/src/lib/filesystem_name.ts b/packages/commons/src/lib/filesystem_name.ts
index 16469b4978..c6f4e0fa7e 100644
--- a/packages/commons/src/lib/filesystem_name.ts
+++ b/packages/commons/src/lib/filesystem_name.ts
@@ -20,7 +20,7 @@
export const FORBIDDEN_FILE_NAME_CHARACTERS = '<>:"/\\|?*';
/** Reserved device names on Windows, which cannot be a file name there whatever the extension. */
-const RESERVED_FILE_NAMES = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
+const RESERVED_FILE_NAMES = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
/**
* Drops every character a file name may not contain, and nothing else.