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

[Bugfix]: 'forbidden_chars' - the condition added for uploading via Drop or UploadPicker. #43495 #43512

20 changes: 15 additions & 5 deletions apps/files/src/services/DropService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import { getUploader } from '@nextcloud/upload'
import { joinPaths } from '@nextcloud/paths'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { loadState } from '@nextcloud/initial-state'

import logger from '../logger.js'

const forbiddenCharacters = loadState<string>('files', 'forbiddenCharacters', '')

export const handleDrop = async (data: DataTransfer): Promise<Upload[]> => {
// TODO: Maybe handle `getAsFileSystemHandle()` in the future

Expand Down Expand Up @@ -67,11 +70,18 @@ export const handleDrop = async (data: DataTransfer): Promise<Upload[]> => {
const handleFileUpload = async (file: File, path: string = '') => {
const uploader = getUploader()

try {
return await uploader.upload(`${path}${file.name}`, file)
} catch (e) {
showError(t('files', 'Uploading "{filename}" failed', { filename: file.name }))
throw e
const forbidden = forbiddenCharacters.split('')
const forbiddenChar = forbidden.find(char => file.name.includes(char))

if (forbiddenChar !== undefined) {
showError(t('files', '"{forbiddenChar}" is not allowed inside a file name.', { forbiddenChar }))
} else {
try {
return await uploader.upload(`${path}${file.name}`, file)
} catch (e) {
showError(t('files', 'Uploading "{filename}" failed', { filename: file.name }))
throw e
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<UploadPicker v-else-if="currentFolder"
:content="dirContents"
:destination="currentFolder"
:forbiddenCharacters="forbiddenCharacters"
:multiple="true"
class="files-list__header-upload-button"
@failed="onUploadFail"
Expand Down Expand Up @@ -213,6 +214,7 @@ export default defineComponent({
loading: true,
promise: null,
Type,
forbiddenCharacters: loadState('files', 'forbiddenCharacters', '') as string,
}
},

Expand Down