From b2a82b64b5714c66f9e0e291b967bcaa536bf041 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Mon, 1 Sep 2025 17:29:54 -0400 Subject: fix: add validation when creating a new tag (#7890) A tag name must be unique and can't be used as a category. There were no error message when creating a tag identical to an existing category. Now, this is addressed. See #7686 Closes #7686 Changes proposed in this pull request: - add validation on tag creation How to test the feature manually: 1. create a new category (ex: `HW`) 2. create a new tag with the same name as the new category (ex: `HW`) 3. validate that the appropriate error message is displayed --- app/Controllers/tagController.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.php index da7e0c2da..47301bba0 100644 --- a/app/Controllers/tagController.php +++ b/app/Controllers/tagController.php @@ -153,14 +153,21 @@ class FreshRSS_tag_Controller extends FreshRSS_ActionController { Minz_Error::error(405); } + $url_redirect = ['c' => 'tag', 'a' => 'index']; $name = Minz_Request::paramString('name'); + + $catDAO = FreshRSS_Factory::createCategoryDao(); + if ($catDAO->searchByName($name) !== null) { + Minz_Request::bad(_t('feedback.sub.category.name_exists'), $url_redirect); + } + $tagDAO = FreshRSS_Factory::createTagDao(); - if (strlen($name) > 0 && null === $tagDAO->searchByName($name)) { - $tagDAO->addTag(['name' => $name]); - Minz_Request::good(_t('feedback.tag.created', $name), ['c' => 'tag', 'a' => 'index']); + if ($tagDAO->searchByName($name) !== null) { + Minz_Request::bad(_t('feedback.tag.name_exists', $name), $url_redirect); } - Minz_Request::bad(_t('feedback.tag.name_exists', $name), ['c' => 'tag', 'a' => 'index']); + $tagDAO->addTag(['name' => $name]); + Minz_Request::good(_t('feedback.tag.created', $name), $url_redirect); } /** -- cgit v1.2.3