Skip to content

Commit

Permalink
fix: don't treat file paths with 7z extension as directories
Browse files Browse the repository at this point in the history
Fixes #71
  • Loading branch information
flakey5 committed Nov 18, 2023
1 parent 0e9ec8b commit 9877d71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 9877d71

Please sign in to comment.