diff --git a/bash-tpl b/bash-tpl index ddca420..eaf7416 100755 --- a/bash-tpl +++ b/bash-tpl @@ -424,19 +424,19 @@ function escape_regex() { local e="${!1}" # Escape '\' first since we'll be adding more after e="${e//\\/\\\\}" - e="${e//'$'/'\$'}" - e="${e//'*'/'\*'}" - e="${e//'+'/'\+'}" - e="${e//'.'/'\.'}" - e="${e//'?'/'\?'}" - e="${e//'^'/'\^'}" - e="${e//'|'/'\|'}" - e="${e//'('/'\('}" - e="${e//')'/'\)'}" - e="${e//'['/'\['}" - e="${e//']'/'\]'}" - e="${e//'{'/'\{'}" - e="${e//'}'/'\}'}" + e="${e//'$'/\\$}" + e="${e//'*'/\\*}" + e="${e//'+'/\\+}" + e="${e//'.'/\\.}" + e="${e//'?'/\\?}" + e="${e//'^'/\\^}" + e="${e//'|'/\\|}" + e="${e//'('/\\(}" + e="${e//')'/\\)}" + e="${e//'['/\\[}" + e="${e//']'/\\]}" + e="${e//'{'/\\{}" + e="${e//'}'/\}}" printf -v "${1}" "%s" "${e}" } diff --git a/test/template-regexes.bats b/test/template-regexes.bats index 5834d4a..aae9987 100644 --- a/test/template-regexes.bats +++ b/test/template-regexes.bats @@ -1395,9 +1395,12 @@ setup() { [[ '<%$%>' =~ $TAG_STATEMENT_REGEX ]] [[ '<%$ %>' =~ $TAG_STATEMENT_REGEX ]] [[ '<%$ %>' =~ $TAG_STATEMENT_REGEX ]] + # shellcheck disable=SC2016 [[ '<%$tag%>' =~ $TAG_STATEMENT_REGEX ]] [[ '<%$ tag%>' =~ $TAG_STATEMENT_REGEX ]] + # shellcheck disable=SC2016 [[ '<%$tag %>' =~ $TAG_STATEMENT_REGEX ]] + # shellcheck disable=SC2016 [[ '<%$ $tag %>' =~ $TAG_STATEMENT_REGEX ]] [[ '<%$$ $%>' =~ $TAG_STATEMENT_REGEX ]] [[ '<%$$ $ %>' =~ $TAG_STATEMENT_REGEX ]]