diff --git a/deno/src/utils.ts b/deno/src/utils.ts index 6ce91c90..f4ae7c78 100644 --- a/deno/src/utils.ts +++ b/deno/src/utils.ts @@ -90,9 +90,8 @@ export async function shortHash(fileName: string): Promise { count++; } - const parts = splitOnce(sub, ".", "right"); - sub = parts[0]; - let ext = parts.at(1); + sub = splitOnce(sub, ".", "right")[0]; + let ext = splitOnce(fileName, ".", "right").at(1); ext = ext ? `.${ext}` : ""; if (sub.length === 0) { diff --git a/deno/tests/utils.test.ts b/deno/tests/utils.test.ts index be4a424c..8bdb4c68 100644 --- a/deno/tests/utils.test.ts +++ b/deno/tests/utils.test.ts @@ -49,11 +49,15 @@ Deno.test("shortHash returns hashed filename for forbidden/long names", async () const result = await shortHash("ThisIsUppercase.txt"); assertMatch(result, /^#thisisuppercase_[a-f0-9]{5}\.txt$/); const result2 = await shortHash("file?name.txt"); - assertMatch(result2, /^#file_[a-f0-9]{5}$/); + assertMatch(result2, /^#file_[a-f0-9]{5}.txt$/); const result3 = await shortHash("a".repeat(40)); assertMatch(result3, /^#aaaaaaaaaaaaaaaaaaaa_[a-f0-9]{5}$/); const result4 = await shortHash("file {