Skip to content

Commit c72c3a1

Browse files
nischiemineohackingharold
authored andcommitted
fix(#97): accept validator case insensitive
Fix issue where accept validator return false if file extension is uppercase. Accept validator should be case insensitive. Closes #97.
1 parent 815839a commit c72c3a1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

projects/cdk/src/lib/file-input/accept.service.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ describe('AcceptService', () => {
2525
expect(accepted).toBeFalse();
2626
});
2727

28+
it('should accept file if extension is uppercase', () => {
29+
const files = [getFile('PDF')];
30+
31+
const acceptedUpper = service.accepts(files, '.PDF');
32+
expect(acceptedUpper).toBeTrue();
33+
34+
const acceptedLower = service.accepts(files, '.pdf');
35+
expect(acceptedLower).toBeTrue();
36+
});
37+
38+
it('should accept file if extension is lowercase', () => {
39+
const files = [getFile('pdf')];
40+
41+
const acceptedUpper = service.accepts(files, '.PDF');
42+
expect(acceptedUpper).toBeTrue();
43+
44+
const acceptedLower = service.accepts(files, '.pdf');
45+
expect(acceptedLower).toBeTrue();
46+
});
47+
2848
it('should filter based on MIME type', () => {
2949
const files = getFileList();
3050
const accepted = service.accepts(files, 'application/msword, application, random/MIME');

projects/cdk/src/lib/file-input/accept.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class AcceptService {
2727
}
2828

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

3333
private isAcceptedByMimeType(file: File, acceptedMimeTypes: string[]): boolean {

0 commit comments

Comments
 (0)