From 2e15f87f6ee5e0a02579afb7838b856b84026fb2 Mon Sep 17 00:00:00 2001 From: d-buchmann Date: Thu, 22 May 2025 15:35:42 +0200 Subject: [PATCH] Tidy up tag deletion --- src/Services/Parts/PartsTableActionHandler.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Services/Parts/PartsTableActionHandler.php b/src/Services/Parts/PartsTableActionHandler.php index 63325e42..55bb9dbb 100644 --- a/src/Services/Parts/PartsTableActionHandler.php +++ b/src/Services/Parts/PartsTableActionHandler.php @@ -140,14 +140,15 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart case "add_tag": $this->denyAccessUnlessGranted('edit', $part); $tags = $part->getTags(); - $part->setTags($tags . ',' . $target_id); // simple append + // simple append + $part->setTags($tags.','.$target_id); break; case "remove_tag": $this->denyAccessUnlessGranted('edit', $part); - $tags = $part->getTags(); - $tags = str_replace($target_id, '', $tags); - // sanitize $tags (remove leading, trailing and double commas) - $part->setTags($tags); + // remove tag at start or end + $tags = preg_replace("/(^".$target_id.",|,".$target_id."$)/", '', $part->getTags()); + // remove tag in the middle, retaining one comma + $tags = str_replace(','.$target_id.',', ',' $tags); break; case 'favorite': $this->denyAccessUnlessGranted('change_favorite', $part);