From 741c414d6afe9e0c5be5b4435e80676ebc99df54 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Wed, 15 Feb 2017 11:01:34 -0500 Subject: [PATCH] preprocess: Use printf -v in encode_name --- libexec/bats-preprocess | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libexec/bats-preprocess b/libexec/bats-preprocess index 873085e..6cd90eb 100755 --- a/libexec/bats-preprocess +++ b/libexec/bats-preprocess @@ -4,6 +4,7 @@ set -e encode_name() { local name="$1" local result="test_" + local hex_code if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then name="${name//_/-5f}" @@ -21,12 +22,13 @@ encode_name() { elif [[ "$char" =~ [[:alnum:]] ]]; then result+="$char" else - result+="$(printf -- "-%02x" \'"$char")" + printf -v 'hex_code' -- "-%02x" \'"$char" + result+="$hex_code" fi done fi - echo "$result" + printf -v "$2" '%s' "$result" } tests=() @@ -40,7 +42,7 @@ while IFS= read -r line; do quoted_name="${BASH_REMATCH[1]}" body="${BASH_REMATCH[2]}" name="$(eval echo "$quoted_name")" - encoded_name="$(encode_name "$name")" + encode_name "$name" 'encoded_name' tests["${#tests[@]}"]="$encoded_name" echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}" else