Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/remote-sources: do not rely on .name property #3941

Merged
merged 2 commits into from Aug 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 7 additions & 14 deletions packages/@uppy/remote-sources/src/index.js
Expand Up @@ -12,7 +12,9 @@ import Zoom from '@uppy/zoom'

import packageJson from '../package.json'

const availablePlugins = [
const availablePlugins = {
// Using a null-prototype object to avoid prototype pollution.
__proto__: null,
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
Box,
Dropbox,
Facebook,
Expand All @@ -22,7 +24,7 @@ const availablePlugins = [
Unsplash,
Url,
Zoom,
]
}

export default class RemoteSources extends BasePlugin {
static VERSION = packageJson.version
Expand All @@ -35,16 +37,7 @@ export default class RemoteSources extends BasePlugin {
this.type = 'acquirer'

const defaultOptions = {
sources: [
'Box',
'Dropbox',
'Facebook',
'GoogleDrive',
'Instagram',
'OneDrive',
'Unsplash',
'Url',
],
sources: Object.keys(availablePlugins),
target: Dashboard,
}
this.opts = { ...defaultOptions, ...opts }
Expand All @@ -63,9 +56,9 @@ export default class RemoteSources extends BasePlugin {
install () {
this.opts.sources.forEach((pluginId) => {
const optsForRemoteSourcePlugin = { ...this.opts, sources: undefined }
const plugin = availablePlugins.find(p => p.name === pluginId)
const plugin = availablePlugins[pluginId]
if (plugin == null) {
const pluginNames = availablePlugins.map(p => p.name)
const pluginNames = Object.keys(availablePlugins)
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' })
throw new Error(`Invalid plugin: "${pluginId}" is not one of: ${formatter.format(pluginNames)}.`)
}
Expand Down