Skip to content

fix(#97): accept validator case insensitive #98

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

Merged
merged 1 commit into from
Nov 20, 2024
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