Skip to content

Commit fd430a6

Browse files
Open up canShare some more (#1906)
* Add in file count check for data.files in canShare * Update check and tests * Lint fix * Make canShare more permissive
1 parent 3819168 commit fd430a6

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

injected/src/features/web-compat.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ const MSG_DEVICE_ENUMERATION = 'deviceEnumeration';
2121

2222
function canShare(data) {
2323
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;
2534
if ('files' in data) {
26-
if (!Array.isArray(data.files)) return false;
35+
if (!(Array.isArray(data.files) || data.files instanceof FileList)) return false;
2736
if (data.files.length > 0) return false; // File sharing is not supported at the moment
2837
}
2938
if ('title' in data && typeof data.title !== 'string') return false;

0 commit comments

Comments
 (0)