diff --git a/apps/files/src/components/FileEntry/FileEntryName.vue b/apps/files/src/components/FileEntry/FileEntryName.vue index 4b387071a4aeb..5411d8657b99a 100644 --- a/apps/files/src/components/FileEntry/FileEntryName.vue +++ b/apps/files/src/components/FileEntry/FileEntryName.vue @@ -223,25 +223,22 @@ export default Vue.extend({ }, isFileNameValid(name) { const trimmedName = name.trim() + const char = trimmedName.indexOf('/') !== -1 + ? '/' + : forbiddenCharacters.find((char) => trimmedName.includes(char)) + if (trimmedName === '.' || trimmedName === '..') { throw new Error(t('files', '"{name}" is an invalid file name.', { name })) } else if (trimmedName.length === 0) { throw new Error(t('files', 'File name cannot be empty.')) - } else if (trimmedName.indexOf('/') !== -1) { - throw new Error(t('files', '"/" is not allowed inside a file name.')) + } else if (char) { + throw new Error(t('files', '"{char}" is not allowed inside a file name.', { char })) } else if (trimmedName.match(OC.config.blacklist_files_regex)) { throw new Error(t('files', '"{name}" is not an allowed filetype.', { name })) } else if (this.checkIfNodeExists(name)) { throw new Error(t('files', '{newName} already exists.', { newName: name })) } - const toCheck = trimmedName.split('') - toCheck.forEach(char => { - if (forbiddenCharacters.indexOf(char) !== -1) { - throw new Error(this.t('files', '"{char}" is not allowed inside a file name.', { char })) - } - }) - return true }, checkIfNodeExists(name) { diff --git a/apps/files/src/components/NewNodeDialog.vue b/apps/files/src/components/NewNodeDialog.vue index 4087b58c607c8..46c39890dc987 100644 --- a/apps/files/src/components/NewNodeDialog.vue +++ b/apps/files/src/components/NewNodeDialog.vue @@ -34,10 +34,12 @@
@@ -48,15 +50,19 @@ import type { PropType } from 'vue' import { defineComponent } from 'vue' import { translate as t } from '@nextcloud/l10n' import { getUniqueName } from '@nextcloud/files' +import { loadState } from '@nextcloud/initial-state' import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js' import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js' +import logger from '../logger.js' interface ICanFocus { focus: () => void } +const forbiddenCharacters = loadState