Skip to content

Commit 3e9b4dd

Browse files
🔧 fix(#75): make validator accept null values.
2 parents a2b6de0 + b422983 commit 3e9b4dd

File tree

7 files changed

+14
-15
lines changed

7 files changed

+14
-15
lines changed

.github/workflows/on-pull-request.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v3
1313
- uses: oven-sh/setup-bun@v1
14-
- run: bun install
14+
- run: bun install --frozen-lockfile
1515

1616
- run: bun run lint:cdk
1717
- run: bun run build:cdk
@@ -22,7 +22,7 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v3
2424
- uses: oven-sh/setup-bun@v1
25-
- run: bun install
25+
- run: bun install --frozen-lockfile
2626

2727
- run: bun run build:cdk
2828
- run: bun run lint:material

.github/workflows/on-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
always-auth: true
2020
token: ${{ secrets.NPM_TOKEN }}
2121
- uses: oven-sh/setup-bun@v1
22-
- run: bun install
22+
- run: bun install --frozen-lockfile
2323

2424
- run: bun run build:cdk
2525
- run: bun run build:material

bun.lockb

-6.64 KB
Binary file not shown.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@types/node": "^20.5.9",
4242
"@typescript-eslint/eslint-plugin": "^6.10.0",
4343
"@typescript-eslint/parser": "^6.10.0",
44+
"ajv": "^8.12.0",
4445
"eslint": "^8.53.0",
4546
"jasmine-core": "~3.8.0",
4647
"karma": "~6.4.2",

projects/cdk/src/lib/dropzone/dropzone.service.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export class DropzoneService {
1616

1717
const fsEntries = Array.from(event.dataTransfer?.items ?? [])
1818
.map((item) => this._toFileSystemEntry(item))
19-
.filter(nonNullable)
20-
.map((entry) => this._getFilesFromEntry(entry));
19+
.map((entry) => this._getFilesFromEntry(entry))
20+
.filter(nonNullable);
2121

2222
const files: File[][] = await Promise.all(fsEntries);
2323
return this._flattenFiles(files);
@@ -34,7 +34,9 @@ export class DropzoneService {
3434
return item.webkitGetAsEntry() || item.getAsFile();
3535
}
3636

37-
private async _getFilesFromEntry(entry: FileSystemEntry | File): Promise<File[]> {
37+
private async _getFilesFromEntry(entry: FileSystemEntry | File | null): Promise<File[]> {
38+
if (!entry) return [];
39+
3840
if (entry instanceof File) {
3941
return [entry];
4042
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('AcceptService', () => {
1111
getFile('doc', 'application/msword'),
1212
getFile('docx', 'application/msword'),
1313
getFile('txt'),
14-
getFile('pdf', 'application/octet-stream')
14+
getFile('pdf', 'application/octet-stream'),
1515
];
1616

1717
beforeEach(() => {
@@ -55,8 +55,8 @@ describe('AcceptService', () => {
5555
expect(accepted).toBeTrue();
5656
});
5757

58-
it('should not accept null', () => {
59-
const accepted = service.accepts(null, '*');
60-
expect(accepted).toBeFalse();
58+
it('should skip filter on null', () => {
59+
const accepted = service.accepts(null, 'image/png');
60+
expect(accepted).toBeTrue();
6161
});
6262
});

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ export class AcceptService {
1111
* for more information.
1212
*/
1313
accepts(fileValue: FileInputValue, accept: string): boolean {
14-
if (!fileValue) {
15-
return false;
16-
}
17-
18-
if (accept === '*') {
14+
if (!fileValue || accept === '*') {
1915
return true;
2016
}
2117

0 commit comments

Comments
 (0)