Skip to content

Commit

Permalink
fix: handle no filename in zip check
Browse files Browse the repository at this point in the history
Fixes the following crash:

> 2024-12-04T13:06:45.039Z - TypeError:
> Cannot read properties of undefined (reading 'trim')
> TypeError: Cannot read properties of undefined (reading 'trim')
  • Loading branch information
aalemayhu committed Dec 5, 2024
1 parent a1ab022 commit 0a14cc5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/lib/storage/checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ test('isPotentialZipFile identifies potential zip files', () => {
expect(isPotentialZipFile(HAS_EXTENSION_TAR_GZ)).toBe(false);
expect(isPotentialZipFile(ENDS_WITH_DOUBLE_PERIOD)).toBe(true);
});

test('isPotentialZipFile handles undefined input gracefully', () => {
expect(isPotentialZipFile(undefined)).toBe(false);
expect(isPotentialZipFile(null)).toBe(false);
expect(isPotentialZipFile('')).toBe(false);
});
7 changes: 6 additions & 1 deletion src/lib/storage/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export const isPPTFile = (fileName: string) => /\.(ppt|pptx)$/i.exec(fileName);
* @param filename
* @returns
*/
export const isPotentialZipFile = (filename: string): boolean => {
export const isPotentialZipFile = (
filename: string | null | undefined
): boolean => {
if (!filename) {
return false;
}
return filename.trim().endsWith('.') || !filename.includes('.');
};
3 changes: 2 additions & 1 deletion src/usecases/uploads/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ function doGenerationWork(data: GenerationData) {
} else if (
isZIPFile(filename) ||
isZIPFile(key) ||
isPotentialZipFile(filename)
isPotentialZipFile(filename) ||
isPotentialZipFile(key)
) {
const { packages: extraPackages } = await getPackagesFromZip(
fileContents,
Expand Down

0 comments on commit 0a14cc5

Please sign in to comment.