Auto escape: Unquote 'bad_char' in string disection (Win: mksh)

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
This commit is contained in:
Richard T Bonhomme 2022-05-28 00:26:03 +01:00
parent 83fa2ac23d
commit d5f349888a
No known key found for this signature in database
GPG Key ID: 2D767DB92FB6C246

View File

@ -652,6 +652,7 @@ make_safe_ssl_copy() {
} # => make_safe_ssl_copy()
# 'sed' behavior with '&' is not modifiable, so auto escape '&'
# shellcheck disable=SC2295 # Expansions inside ${..} need to be quoted ..
escape_char() {
bad_char="$1"
in_str="$2"
@ -660,26 +661,24 @@ escape_char() {
part_head=""
part_next=""
part_temp=""
esc_char=\\
# shell###check disable=SC1003 # Want to escape a single quote? No..
esc_char='\'
part_head="${in_str%%"${bad_char}"*}" # Drop RHS
part_head="${in_str%%${bad_char}*}" # Drop RHS
if [ "$part_head" = "$in_str" ]; then
# ok - No borken chars found
out_str="${part_head}"
else
part_head="${part_head}${esc_char}${bad_char}" # Insert ESC+char
while [ "$part_full_rhs" ]; do
part_full_rhs="${part_full_rhs#*"${bad_char}"}" # Drop LHS
part_next="${part_full_rhs%%"${bad_char}"*}" # Drop RHS
part_full_rhs="${part_full_rhs#*${bad_char}}" # Drop LHS
part_next="${part_full_rhs%%${bad_char}*}" # Drop RHS
if [ "$part_next" = "$part_full_rhs" ]; then
# ok - No borken chars found
part_full_rhs=""
part_temp="${part_temp}${part_next}"
else
part_full_rhs="${part_full_rhs#*"${bad_char}"}" # Drop LHS
part_full_rhs="${part_full_rhs#*${bad_char}}" # Drop LHS
part_next="${part_next}${esc_char}${bad_char}" # Insert ESC+char
part_temp="${part_temp}${part_next}"
fi