Skip to content

Commit

Permalink
fix: handle zip files ending with ' .'
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Dec 4, 2024
1 parent ac20e01 commit f050cb5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
28 changes: 24 additions & 4 deletions src/lib/storage/checks.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { hasMarkdownFileName } from './checks';
import { hasMarkdownFileName, isPotentialZipFile } from './checks';

const FILE_MD = 'abc.md';
const FILE_TXT = 'def.txt';
const FILE_MD_UPPER = 'cool.MD';

const NO_EXTENSION = 'file';
const ENDS_WITH_PERIOD = 'file.';
const HAS_EXTENSION_ZIP = 'file.zip';
const HAS_EXTENSION_TXT = 'file.txt';
const HAS_EXTENSION_TAR_GZ = 'file.tar.gz';
const ENDS_WITH_DOUBLE_PERIOD = 'file..';

test('hasMarkdownFileName returns true', () => {
expect(hasMarkdownFileName(['abc.md', 'def.txt'])).toBe(true);
expect(hasMarkdownFileName(['cool.MD'])).toBe(true);
expect(hasMarkdownFileName([FILE_MD, FILE_TXT])).toBe(true);
expect(hasMarkdownFileName([FILE_MD_UPPER])).toBe(true);
});

test('hasMarkdownFileName returns false', () => {
expect(hasMarkdownFileName(['abc.txt', 'def.txt'])).toBe(false);
expect(hasMarkdownFileName([FILE_TXT, FILE_TXT])).toBe(false);
});

test('isPotentialZipFile identifies potential zip files', () => {
expect(isPotentialZipFile(NO_EXTENSION)).toBe(true);
expect(isPotentialZipFile(ENDS_WITH_PERIOD)).toBe(true);
expect(isPotentialZipFile(HAS_EXTENSION_ZIP)).toBe(false);
expect(isPotentialZipFile(HAS_EXTENSION_TXT)).toBe(false);
expect(isPotentialZipFile(HAS_EXTENSION_TAR_GZ)).toBe(false);
expect(isPotentialZipFile(ENDS_WITH_DOUBLE_PERIOD)).toBe(true);
});
5 changes: 3 additions & 2 deletions src/lib/storage/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export const isPDFFile = (fileName: string) => /.pdf$/i.exec(fileName);
* @param filename
* @returns
*/
export const isPotentialZipFile = (filename: string): boolean =>
!filename.includes('.');
export const isPotentialZipFile = (filename: string): boolean => {
return filename.trim().endsWith('.') || !filename.includes('.');
};

0 comments on commit f050cb5

Please sign in to comment.