Skip to content
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
20 changes: 20 additions & 0 deletions projects/cdk/src/lib/file-input/accept.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ describe('AcceptService', () => {
expect(accepted).toBeFalse();
});

it('should accept file if extension is uppercase', () => {
const files = [getFile('PDF')];

const acceptedUpper = service.accepts(files, '.PDF');
expect(acceptedUpper).toBeTrue();

const acceptedLower = service.accepts(files, '.pdf');
expect(acceptedLower).toBeTrue();
});

it('should accept file if extension is lowercase', () => {
const files = [getFile('pdf')];

const acceptedUpper = service.accepts(files, '.PDF');
expect(acceptedUpper).toBeTrue();

const acceptedLower = service.accepts(files, '.pdf');
expect(acceptedLower).toBeTrue();
});

it('should filter based on MIME type', () => {
const files = getFileList();
const accepted = service.accepts(files, 'application/msword, application, random/MIME');
Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/src/lib/file-input/accept.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AcceptService {
}

private isAcceptedByExtension(file: File, acceptedExtensions: string[]): boolean {
return acceptedExtensions.some((ext) => file.name.endsWith(ext));
return acceptedExtensions.some((ext) => file.name.toLowerCase().endsWith(ext));
}

private isAcceptedByMimeType(file: File, acceptedMimeTypes: string[]): boolean {
Expand Down
Loading