File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ const mockAdapter = {
16
16
deleteFile : ( ) => { } ,
17
17
getFileData : ( ) => { } ,
18
18
getFileLocation : ( ) => 'xyz' ,
19
- validateFilename : ( ) => { } ,
19
+ validateFilename : ( ) => {
20
+ return null ;
21
+ } ,
20
22
} ;
21
23
22
24
// Small additional tests to improve overall coverage
@@ -77,6 +79,19 @@ describe('FilesController', () => {
77
79
} ) ;
78
80
} ) ;
79
81
82
+ it ( 'should create a parse error when a string is returned' , done => {
83
+ const mock2 = mockAdapter ;
84
+ mock2 . validateFilename = ( ) => {
85
+ return 'Bad file! No biscuit!' ;
86
+ } ;
87
+ const filesController = new FilesController ( mockAdapter ) ;
88
+ const error = filesController . validateFilename ( ) ;
89
+ expect ( typeof error ) . toBe ( 'object' ) ;
90
+ expect ( error . message . indexOf ( 'biscuit' ) ) . toBe ( 13 ) ;
91
+ expect ( error . code ) . toBe ( Parse . Error . INVALID_FILE_NAME ) ;
92
+ done ( ) ;
93
+ } ) ;
94
+
80
95
it ( 'should add a unique hash to the file name when the preserveFileName option is false' , done => {
81
96
const config = Config . get ( Parse . applicationId ) ;
82
97
const gridStoreAdapter = new GridFSBucketAdapter (
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import AdaptableController from './AdaptableController';
4
4
import { validateFilename , FilesAdapter } from '../Adapters/Files/FilesAdapter' ;
5
5
import path from 'path' ;
6
6
import mime from 'mime' ;
7
+ const Parse = require ( 'parse' ) . Parse ;
7
8
8
9
const legacyFilesRegex = new RegExp (
9
10
'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}-.*'
@@ -98,7 +99,11 @@ export class FilesController extends AdaptableController {
98
99
99
100
validateFilename ( filename ) {
100
101
if ( typeof this . adapter . validateFilename === 'function' ) {
101
- return this . adapter . validateFilename ( filename ) ;
102
+ const error = this . adapter . validateFilename ( filename ) ;
103
+ if ( typeof error !== 'string' ) {
104
+ return error ;
105
+ }
106
+ return new Parse . Error ( Parse . Error . INVALID_FILE_NAME , error ) ;
102
107
}
103
108
return validateFilename ( filename ) ;
104
109
}
You can’t perform that action at this time.
0 commit comments