@@ -17,10 +17,12 @@ const utils = {
17
17
toStringArray ( value :any ) :string [ ] {
18
18
if ( Array . isArray ( value ) ) return value ;
19
19
if ( typeof value === 'string' ) return value . trim ( ) . split ( / \s * [ ; , ] \s * / ) ;
20
- throw new Error ( 'Cannot convert value to array!' ) ;
20
+ // throw new Error('Cannot convert value to array!');
21
+ return null ;
21
22
} ,
22
23
23
24
isFilledStringArray ( arr :any [ ] ) :boolean {
25
+ if ( ! arr || ! Array . isArray ( arr ) ) return false ;
24
26
for ( let s of arr ) {
25
27
if ( typeof s !== 'string' || s . trim ( ) === '' ) return false ;
26
28
}
@@ -56,6 +58,7 @@ const utils = {
56
58
*/
57
59
getFlatRoles ( grants :any , roles :string | string [ ] ) :string [ ] {
58
60
roles = utils . toStringArray ( roles ) ;
61
+ if ( ! roles ) throw new AccessControlError ( `Invalid role(s): ${ JSON . stringify ( roles ) } ` ) ;
59
62
let arr :string [ ] = roles . concat ( ) ;
60
63
roles . forEach ( ( roleName :string ) => {
61
64
let role :any = grants [ roleName ] ;
@@ -302,12 +305,14 @@ const utils = {
302
305
*/
303
306
extendRole ( grants :any , roles :string | string [ ] , extenderRoles :string | string [ ] ) {
304
307
let arrExtRoles :string [ ] = utils . toStringArray ( extenderRoles ) ;
308
+ if ( ! arrExtRoles ) throw new AccessControlError ( `Invalid extender role(s): ${ JSON . stringify ( extenderRoles ) } ` ) ;
305
309
let nonExistentExtRoles :string [ ] = utils . getNonExistentRoles ( grants , arrExtRoles ) ;
306
310
if ( nonExistentExtRoles . length > 0 ) {
307
311
throw new AccessControlError ( `Cannot extend with non-existent role(s): "${ nonExistentExtRoles . join ( ', ' ) } "` ) ;
308
312
}
309
-
310
- utils . toStringArray ( roles ) . forEach ( ( role :string ) => {
313
+ roles = utils . toStringArray ( roles ) ;
314
+ if ( ! roles ) throw new AccessControlError ( `Invalid role(s): ${ JSON . stringify ( roles ) } ` ) ;
315
+ roles . forEach ( ( role :string ) => {
311
316
if ( arrExtRoles . indexOf ( role ) >= 0 ) {
312
317
throw new AccessControlError ( `Attempted to extend role "${ role } " by itself.` ) ;
313
318
}
0 commit comments