From 540927a956ad1e9e3d21f7dfe760de88fb473430 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Thu, 1 Aug 2019 13:15:58 +0200 Subject: [PATCH] Trim titles/names before saving #1836 --- i18n/translations/en.json | 1 + panel/src/components/Dialogs/FileRenameDialog.vue | 8 ++++++++ panel/src/components/Dialogs/PageCreateDialog.vue | 2 ++ panel/src/components/Dialogs/PageRenameDialog.vue | 2 ++ panel/src/components/Dialogs/UserRenameDialog.vue | 2 ++ 5 files changed, 15 insertions(+) diff --git a/i18n/translations/en.json b/i18n/translations/en.json index 98bf41b5f4..5cafd822dd 100644 --- a/i18n/translations/en.json +++ b/i18n/translations/en.json @@ -51,6 +51,7 @@ "error.field.converter.invalid": "Invalid converter \"{converter}\"", + "error.file.changeName.empty": "The name must not be empty", "error.file.changeName.permission": "You are not allowed to change the name of \"{filename}\"", "error.file.duplicate": "A file with the name \"{filename}\" already exists", diff --git a/panel/src/components/Dialogs/FileRenameDialog.vue b/panel/src/components/Dialogs/FileRenameDialog.vue index aeebcb28eb..f681aac943 100644 --- a/panel/src/components/Dialogs/FileRenameDialog.vue +++ b/panel/src/components/Dialogs/FileRenameDialog.vue @@ -72,6 +72,14 @@ export default { return slug(input, [this.slugs, this.system.ascii], "."); }, submit() { + // prevent empty name with just spaces + this.file.name = this.file.name.trim(); + + if (this.file.name.length === 0) { + this.$refs.dialog.error(this.$t("error.file.changeName.empty")); + return; + } + this.$api.files .rename(this.parent, this.file.filename, this.file.name) .then(file => { diff --git a/panel/src/components/Dialogs/PageCreateDialog.vue b/panel/src/components/Dialogs/PageCreateDialog.vue index d6ccba19e7..a8d8bffc2f 100644 --- a/panel/src/components/Dialogs/PageCreateDialog.vue +++ b/panel/src/components/Dialogs/PageCreateDialog.vue @@ -107,6 +107,8 @@ export default { }, submit() { + // prevent empty title with just spaces + this.page.title = this.page.title.trim(); if (this.page.title.length === 0) { this.$refs.dialog.error('Please enter a title'); diff --git a/panel/src/components/Dialogs/PageRenameDialog.vue b/panel/src/components/Dialogs/PageRenameDialog.vue index 68cedd57de..b3095b47f3 100644 --- a/panel/src/components/Dialogs/PageRenameDialog.vue +++ b/panel/src/components/Dialogs/PageRenameDialog.vue @@ -53,6 +53,8 @@ export default { }); }, submit() { + // prevent empty title with just spaces + this.page.title = this.page.title.trim(); if (this.page.title.length === 0) { this.$refs.dialog.error(this.$t("error.page.changeTitle.empty")); diff --git a/panel/src/components/Dialogs/UserRenameDialog.vue b/panel/src/components/Dialogs/UserRenameDialog.vue index 23d4c9a4f2..7c7ef101da 100644 --- a/panel/src/components/Dialogs/UserRenameDialog.vue +++ b/panel/src/components/Dialogs/UserRenameDialog.vue @@ -52,6 +52,8 @@ export default { }); }, submit() { + this.user.name = this.user.name.trim(); + this.$api.users .changeName(this.user.id, this.user.name) .then(() => {