mirror of
https://github.com/reecetech/version-increment.git
synced 2026-08-18 11:07:50 +00:00
Treat tag prefixes as literal strings
Prevent regex metacharacters and sed delimiters in a tag prefix from selecting unintended tags or causing lookup failures.
This commit is contained in:
18
shared.sh
18
shared.sh
@@ -20,19 +20,13 @@ pcre_old_calver='^(?P<major>0|[1-9]\d*)-0{0,1}(?P<minor>0|[0-9]\d*)-R(?P<patch>0
|
|||||||
remove_prefix() {
|
remove_prefix() {
|
||||||
local tag="$1"
|
local tag="$1"
|
||||||
if [[ -n "${tag_prefix:-}" ]]; then
|
if [[ -n "${tag_prefix:-}" ]]; then
|
||||||
# Escape special characters in tag_prefix
|
if [[ "${tag}" == "${tag_prefix}"* ]]; then
|
||||||
local escaped_prefix
|
printf '%s\n' "${tag:${#tag_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
|
|
||||||
fi
|
|
||||||
# shellcheck disable=SC2001
|
|
||||||
echo "${tag}" | sed "s|^${escaped_prefix}||" # Use | as the delimiter to avoid conflicts with /
|
|
||||||
else
|
else
|
||||||
echo "${tag}"
|
printf '\n'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printf '%s\n' "${tag}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user