1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-05 19:35:48 +03:00

Improve quote_args output readability

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman
2024-02-15 16:04:36 +00:00
parent d4a5563417
commit 634fe908b7
2 changed files with 10 additions and 6 deletions

View File

@@ -24,12 +24,14 @@ quote_args() {
local args=("$@") local args=("$@")
s="" s=""
for a in "${args[@]}"; do for a in "${args[@]}"; do
simple_pattern='^[[:alnum:] _=+-]*$' simple_pattern='^([[:alnum:]_+-]+=)?([[:alnum:] _=+-]*)$'
if [[ $a =~ ' ' && $a =~ $simple_pattern ]]; then if [[ $a =~ ' ' && $a =~ $simple_pattern ]]; then
# a has spaces, but no other special characters that need escaping # a has spaces, but no other special characters that need escaping
# (quoting after removing spaces yields no backslashes) # (quoting after removing spaces yields no backslashes)
# simplify quoted form to "$a" - e.g. yield "a b c" instead of a\ b\ c # simplify quoted form - e.g.:
q="\"$a\"" # a b -> "a b"
# CFLAGS=a b -> CFLAGS="a b"
q="${BASH_REMATCH[1]}\"${BASH_REMATCH[2]}\""
else else
# get bash to do the quoting # get bash to do the quoting
q=$(printf '%q' "$a") q=$(printf '%q' "$a")

View File

@@ -24,12 +24,14 @@ quote_args() {
local args=("$@") local args=("$@")
s="" s=""
for a in "${args[@]}"; do for a in "${args[@]}"; do
simple_pattern='^[[:alnum:] _=+-]*$' simple_pattern='^([[:alnum:]_+-]+=)?([[:alnum:] _=+-]*)$'
if [[ $a =~ ' ' && $a =~ $simple_pattern ]]; then if [[ $a =~ ' ' && $a =~ $simple_pattern ]]; then
# a has spaces, but no other special characters that need escaping # a has spaces, but no other special characters that need escaping
# (quoting after removing spaces yields no backslashes) # (quoting after removing spaces yields no backslashes)
# simplify quoted form to "$a" - e.g. yield "a b c" instead of a\ b\ c # simplify quoted form - e.g.:
q="\"$a\"" # a b -> "a b"
# CFLAGS=a b -> CFLAGS="a b"
q="${BASH_REMATCH[1]}\"${BASH_REMATCH[2]}\""
else else
# get bash to do the quoting # get bash to do the quoting
q=$(printf '%q' "$a") q=$(printf '%q' "$a")