From 1b05caeb4c4d33c06ca3004dc8464a24df9bbac2 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Mon, 10 Aug 2026 15:22:02 +1000 Subject: [PATCH] Treat tag prefixes as literal strings Prevent regex metacharacters and sed delimiters in a tag prefix from selecting unintended tags or causing lookup failures. --- shared.sh | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/shared.sh b/shared.sh index e1624ce..c4bfb11 100644 --- a/shared.sh +++ b/shared.sh @@ -20,19 +20,13 @@ pcre_old_calver='^(?P0|[1-9]\d*)-0{0,1}(?P0|[0-9]\d*)-R(?P0 remove_prefix() { local tag="$1" if [[ -n "${tag_prefix:-}" ]]; then - # Escape special characters in tag_prefix - local escaped_prefix - escaped_prefix=$(printf '%s\n' "$tag_prefix" | sed 's/[][\/.^$*]/\\&/g') # special chars matched by sed: ] [ / . ^ $ * - - # shellcheck disable=SC2143 - if [[ -z "$(echo "${tag}" | grep "^${tag_prefix}")" ]] ; then - echo "" - return + if [[ "${tag}" == "${tag_prefix}"* ]]; then + printf '%s\n' "${tag:${#tag_prefix}}" + else + printf '\n' fi - # shellcheck disable=SC2001 - echo "${tag}" | sed "s|^${escaped_prefix}||" # Use | as the delimiter to avoid conflicts with / else - echo "${tag}" + printf '%s\n' "${tag}" fi }