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('files', 'forbiddenCharacters', '') as string
arublov marked this conversation as resolved.
Show resolved Hide resolved

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('')
let forbiddenChar

if(forbiddenChar = forbidden.find(char => file.name.includes(char))){
arublov marked this conversation as resolved.
Show resolved Hide resolved
arublov marked this conversation as resolved.
Show resolved Hide resolved
showError(t('files', `"${forbiddenChar}" is not allowed inside a file name.`));
arublov marked this conversation as resolved.
Show resolved Hide resolved
}else{
arublov marked this conversation as resolved.
Show resolved Hide resolved
try {
return await uploader.upload(`${path}${file.name}`, file)
} catch (e) {
showError(t('files', 'Uploading "{filename}" failed', { filename: file.name }))
throw e
}
}
}

Expand Down
6 changes: 6 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 @@ -161,6 +162,7 @@ import logger from '../logger.js'
import DragAndDropNotice from '../components/DragAndDropNotice.vue'

const isSharingEnabled = (getCapabilities() as { files_sharing?: boolean })?.files_sharing !== undefined
const forbiddenCharacters = loadState('files', 'forbiddenCharacters', '') as string

export default defineComponent({
name: 'FilesList',
Expand Down Expand Up @@ -402,6 +404,10 @@ export default defineComponent({
return isSharingEnabled
&& this.currentFolder && (this.currentFolder.permissions & Permission.SHARE) !== 0
},

forbiddenCharacters(): string {
return forbiddenCharacters
},
arublov marked this conversation as resolved.
Show resolved Hide resolved
},

watch: {
Expand Down
Loading