Skip to content

Commit 2e15f87

Browse files
committed
Tidy up tag deletion
1 parent 26ee564 commit 2e15f87

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/Services/Parts/PartsTableActionHandler.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,15 @@ public function handleAction(string $action, array $selected_parts, ?string $tar
140140
case "add_tag":
141141
$this->denyAccessUnlessGranted('edit', $part);
142142
$tags = $part->getTags();
143-
$part->setTags($tags . ',' . $target_id); // simple append
143+
// simple append
144+
$part->setTags($tags.','.$target_id);
144145
break;
145146
case "remove_tag":
146147
$this->denyAccessUnlessGranted('edit', $part);
147-
$tags = $part->getTags();
148-
$tags = str_replace($target_id, '', $tags);
149-
// sanitize $tags (remove leading, trailing and double commas)
150-
$part->setTags($tags);
148+
// remove tag at start or end
149+
$tags = preg_replace("/(^".$target_id.",|,".$target_id."$)/", '', $part->getTags());
150+
// remove tag in the middle, retaining one comma
151+
$tags = str_replace(','.$target_id.',', ',' $tags);
151152
break;
152153
case 'favorite':
153154
$this->denyAccessUnlessGranted('change_favorite', $part);

0 commit comments

Comments
 (0)