From c86f04a50a8e5fbfa2a4e243a5cd3964a9b935c2 Mon Sep 17 00:00:00 2001 From: d-buchmann Date: Fri, 23 May 2025 13:28:37 +0200 Subject: [PATCH] fix typo and cleanup --- src/Services/Parts/PartsTableActionHandler.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Services/Parts/PartsTableActionHandler.php b/src/Services/Parts/PartsTableActionHandler.php index 55bb9dbb..584c41e2 100644 --- a/src/Services/Parts/PartsTableActionHandler.php +++ b/src/Services/Parts/PartsTableActionHandler.php @@ -69,13 +69,11 @@ final class PartsTableActionHandler */ public function handleAction(string $action, array $selected_parts, ?string $target_id, ?string $redirect_url = null, array &$errors = []): ?RedirectResponse { - // sanitize target_id - if (!str_contains($action, 'tag') && $target_id !== null) - { - if (!is_numeric($target_id) + // validate target_id + if (!str_contains($action, 'tag') && $target_id !== null && !is_numeric($target_id)) throw new InvalidArgumentException('$target_id must be an integer for action'. $action.'!'); } - + if ($action === 'add_to_project') { return new RedirectResponse( $this->urlGenerator->generate('project_add_parts', [ @@ -145,10 +143,10 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart break; case "remove_tag": $this->denyAccessUnlessGranted('edit', $part); - // 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); + // remove any matching tag at start or end + $tags = preg_replace('/(^'.$target_id.',|,'.$target_id.'$)/', '', $part->getTags()); + // remove any matching tags in the middle, retaining one comma, and commit + $part->setTags(str_replace(','.$target_id.',', ',' $tags); break; case 'favorite': $this->denyAccessUnlessGranted('change_favorite', $part);