File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,18 @@ const MSG_DEVICE_ENUMERATION = 'deviceEnumeration';
21
21
22
22
function canShare ( data ) {
23
23
if ( typeof data !== 'object' ) return false ;
24
- if ( ! ( 'url' in data ) && ! ( 'title' in data ) && ! ( 'text' in data ) ) return false ; // At least one of these is required
24
+ // Make an in-place shallow copy of the data
25
+ data = Object . assign ( { } , data ) ;
26
+ // Delete undefined or null values
27
+ for ( const key of [ 'url' , 'title' , 'text' , 'files' ] ) {
28
+ if ( data [ key ] === undefined || data [ key ] === null ) {
29
+ delete data [ key ] ;
30
+ }
31
+ }
32
+ // After pruning we should still have at least one of these
33
+ if ( ! ( 'url' in data ) && ! ( 'title' in data ) && ! ( 'text' in data ) ) return false ;
25
34
if ( 'files' in data ) {
26
- if ( ! Array . isArray ( data . files ) ) return false ;
35
+ if ( ! ( Array . isArray ( data . files ) || data . files instanceof FileList ) ) return false ;
27
36
if ( data . files . length > 0 ) return false ; // File sharing is not supported at the moment
28
37
}
29
38
if ( 'title' in data && typeof data . title !== 'string' ) return false ;
You can’t perform that action at this time.
0 commit comments