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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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))){
showError(t('files', `"${forbiddenChar}" is not allowed inside a file name.`));
}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
6 changes: 6 additions & 0 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

<!-- Uploader -->
<UploadPicker v-else-if="currentFolder"
:forbiddenCharacters="forbiddenCharacters"
:content="dirContents"
:destination="currentFolder"
:multiple="true"
Expand Down Expand Up @@ -160,6 +161,7 @@ import filesSortingMixin from '../mixins/filesSorting.ts'
import logger from '../logger.js'
import DragAndDropNotice from '../components/DragAndDropNotice.vue'

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

export default defineComponent({
Expand Down Expand Up @@ -248,6 +250,10 @@ export default defineComponent({
return this.filesStore.getNode(fileId)
},

forbiddenCharacters(): string {
return forbiddenCharacters
},

/**
* Directory content sorting parameters
* Provided by an extra computed property for caching
Expand Down