Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't treat file paths with 7z extension as directories #81

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading