From eb4ea50c8dfb49fb7e444427776ae244f24e2510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Ku=C5=BEila?= Date: Sun, 27 Oct 2024 20:36:32 +0100 Subject: [PATCH] fix: validate group name Signed-off-by: Dominik Kuzila --- AUTHORS.md | 1 + src/components/AppNavigation/RootNavigation.vue | 10 +++++++--- src/store/groups.js | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index acf0a4bbd..edc560bf1 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -9,6 +9,7 @@ - Christian Kraus - Christoph Wurst - Daniel Kesselberg +- Dominik Kuzila - Gary Kim - Georg Ehrke - Greta Doci diff --git a/src/components/AppNavigation/RootNavigation.vue b/src/components/AppNavigation/RootNavigation.vue index 627fa9ff9..c92d9c42c 100644 --- a/src/components/AppNavigation/RootNavigation.vue +++ b/src/components/AppNavigation/RootNavigation.vue @@ -393,10 +393,14 @@ export default { this.createGroupError = null this.logger.debug('Created new local group', { groupName }) - this.$store.dispatch('addGroup', groupName) - this.isNewGroupMenuOpen = false - emit('contacts:group:append', groupName) + try { + this.$store.dispatch('addGroup', groupName) + this.isNewGroupMenuOpen = false + emit('contacts:group:append', groupName) + } catch (error) { + showError(t('contacts', 'An error occurred while creating the group')) + } }, // Ellipsis item toggles diff --git a/src/store/groups.js b/src/store/groups.js index 4da839e2d..44de3e214 100644 --- a/src/store/groups.js +++ b/src/store/groups.js @@ -184,6 +184,9 @@ const actions = { * @param {string} groupName the name of the group */ addGroup(context, groupName) { + if (!groupName || groupName.trim() === '') { + throw new Error('Group name cannot be empty') + } context.commit('addGroup', groupName) }, }