From 9877d71a208748ede6fbd4dbb0f838ccd55bac25 Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:33:33 -0800 Subject: [PATCH] fix: don't treat file paths with 7z extension as directories Fixes #71 --- src/util.ts | 17 ++++------------- tests/unit/util.test.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/util.ts b/src/util.ts index b12e949..907495d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -217,19 +217,10 @@ export function isExtensionless(path: string): boolean { const fileExtension = path.substring(extensionDelimiter + 1); // +1 to remove the `.` - // `latest-vXX.x` directory - if (fileExtension.toLowerCase() === 'x') { - return true; - } - - // `vX.X.X` directory - // File extensions generally aren't numbers, so if we can parse this to - // one we can be pretty certain that it's a directory - if (!isNaN(Number.parseInt(fileExtension))) { - return true; - } - - return false; + // This handles the two exceptions + // Either fileExtension === 'x' or we can parse it to a number successfully, + // since generally file extensions aren't numbers + return /^([a-z]|\d+)$/i.test(fileExtension); } /** diff --git a/tests/unit/util.test.ts b/tests/unit/util.test.ts index 5c7ead3..77a80c0 100644 --- a/tests/unit/util.test.ts +++ b/tests/unit/util.test.ts @@ -220,6 +220,14 @@ describe('isDirectoryPath', () => { it('returns false for `/dist/index.json`', () => { assert.strictEqual(isDirectoryPath('/dist/index.json'), false); }); + + // https://github.com/nodejs/release-cloudflare-worker/issues/71 + it('returns false for `/download/release/latest/win-x64/node_pdb.7z`', () => { + assert.strictEqual( + isDirectoryPath('/download/release/latest/win-x64/node_pdb.7z'), + false + ); + }); }); describe('niceBytes', () => {