From a89d8343204f9a0be6fe130c7ec7b017664bdcd1 Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Fri, 12 May 2023 14:48:21 +0300 Subject: [PATCH] bash: be v4.2 compat the replacement string in double-quoted pattern substitution does not undergo quote removal, as it does in versions after bash-4.2 --- shared/macros/10-bash.jinja | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/shared/macros/10-bash.jinja b/shared/macros/10-bash.jinja index 9c5243c6bbc..8c94f264ace 100644 --- a/shared/macros/10-bash.jinja +++ b/shared/macros/10-bash.jinja @@ -38,7 +38,7 @@ There is bash_sed_escape_replacement for replacement escape. Then escape other than \w and ^ with [ ]. And then ^ with \^. And use bash replacement to remove \n. -#}} -{{{ result_variable }}}="$(LC_ALL=C sed 's/[\x01-\x08\x0a-\x1f\x7f]/ /g;s/[^^a-zA-Z0-9_]/[&]/g;s/\^/\\^/g' <<< "{{{ "${" ~ variable ~ "//[$'\n']/ }" }}}")" +{{{ result_variable }}}="$(LC_ALL=C sed 's/[\x01-\x08\x0a-\x1f\x7f]/ /g;s/[^^a-zA-Z0-9_]/[&]/g;s/\^/\\^/g' <<< "{{{ "${" ~ variable ~ "}" }}}" | tr '\n' ' ')" {{%- endmacro -%}} @@ -55,9 +55,7 @@ Any control characters are replaced with space except \0 (null character) and #}} {{%- macro bash_sed_escape_replacement(variable, result_variable, delim="/") -%}} -{{{ result_variable }}}="{{{ "${" ~ variable }}}//\\/\\\\/}" -{{{ result_variable }}}="{{{ "${" ~ result_variable }}}//[$'\x01-\x08\x0a-\x1f\x7f']/ }" -{{{ result_variable }}}="{{{ "${" ~ result_variable }}}//\{{{ delim }}}/\\\{{{ delim ~ "}" }}}" +{{{ result_variable }}}="$(LC_ALL=C sed 's/[\x01-\x08\x0a-\x1f\x7f]/ /g;s/\\/\\\\/g' <<< "{{{ "${" ~ variable }}}//\{{{ delim }}}/\\\{{{ delim ~ "}" }}}")" {{%- endmacro -%}} @@ -1557,8 +1555,7 @@ grep_command+=(-i) # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. -stripped_key="{{{ key }}}" -stripped_key="${stripped_key//[$'^=$,;+']}" +stripped_key="$(LC_ALL=C sed 's/[\^=$,;+]//g' <<< "{{{ key }}}")" # shellcheck disable=SC2059 printf -v formatted_output "{{{ format }}}" "${stripped_key}" "{{{ value }}}"