Skip to content

Commit 44899cf

Browse files
authored
Fix shortHash extension handling (#467)
Ensure the original file extension is preserved when hashing filenames
1 parent aaee3e7 commit 44899cf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

deno/src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ export async function shortHash(fileName: string): Promise<string> {
9090
count++;
9191
}
9292

93-
const parts = splitOnce(sub, ".", "right");
94-
sub = parts[0];
95-
let ext = parts.at(1);
93+
sub = splitOnce(sub, ".", "right")[0];
94+
let ext = splitOnce(fileName, ".", "right").at(1);
9695
ext = ext ? `.${ext}` : "";
9796

9897
if (sub.length === 0) {

deno/tests/utils.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ Deno.test("shortHash returns hashed filename for forbidden/long names", async ()
4949
const result = await shortHash("ThisIsUppercase.txt");
5050
assertMatch(result, /^#thisisuppercase_[a-f0-9]{5}\.txt$/);
5151
const result2 = await shortHash("file?name.txt");
52-
assertMatch(result2, /^#file_[a-f0-9]{5}$/);
52+
assertMatch(result2, /^#file_[a-f0-9]{5}.txt$/);
5353
const result3 = await shortHash("a".repeat(40));
5454
assertMatch(result3, /^#aaaaaaaaaaaaaaaaaaaa_[a-f0-9]{5}$/);
5555
const result4 = await shortHash("file<name.ts");
5656
assertMatch(result4, /^#file_name_[a-f0-9]{5}.ts$/);
57+
const result5 = await shortHash(
58+
"unstable_get_network_address.ts",
59+
);
60+
assertEquals(result5, "#unstable_get_network_b61b7.ts");
5761
});
5862

5963
Deno.test("shortHash returns hashed filename for empty string", async () => {

0 commit comments

Comments
 (0)