Skip to content

Commit

Permalink
@uppy/remote-sources: do not rely on .name property (#3941)
Browse files Browse the repository at this point in the history
Minifiers may be tempted to overwrite the `.name` property of the
plugin classes to save some bytes.
  • Loading branch information
aduh95 committed Aug 3, 2022
1 parent 5fca617 commit ed86eef
Showing 1 changed file with 7 additions and 14 deletions.
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,
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

0 comments on commit ed86eef

Please sign in to comment.