From dc8bd92d5faae8b587f525f54929cf9d9fae9eee Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sun, 1 Nov 2015 21:43:31 +0100 Subject: [PATCH] gl/funclib.sh: func_quotefast_eval & tilde fix Testsuite detected that printf built-in in Bash up to 4.2 was not able to properly escape tilde. * gl/build-aux/funclib.sh (func_quote_for_eval): If printf supports -v option, test also whether we properly escape tilde. With Bash <= 4.2, call func_quote_portable with ~* strings. * bootstrap: Sync with funclib.sh. --- bootstrap | 27 ++++++++++++++++++++++----- gl/build-aux/funclib.sh | 27 ++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/bootstrap b/bootstrap index 1d86ab023..6d62fb6fc 100755 --- a/bootstrap +++ b/bootstrap @@ -230,7 +230,7 @@ vc_ignore= # Source required external libraries: # Set a version string for this script. -scriptversion=2015-10-12.13; # UTC +scriptversion=2015-11-01.21; # UTC # General shell script boiler plate, and helper functions. # Written by Gary V. Vaughan, 2004 @@ -1337,10 +1337,27 @@ func_quote_portable () # Quote one ARG (internal). This is equivalent to 'func_quote_arg eval ARG', # but optimized for speed. Result is stored in $func_quotefast_eval. if test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then - func_quotefast_eval () - { - printf -v func_quotefast_eval_result %q "$1" - } + printf -v _GL_test_printf_tilde %q '~' + if test '\~' = "$_GL_test_printf_tilde"; then + func_quotefast_eval () + { + printf -v func_quotefast_eval_result %q "$1" + } + else + # Broken older Bash implementations. Make those faster too if possible. + func_quotefast_eval () + { + case $1 in + '~'*) + func_quote_portable false "$1" + func_quotefast_eval_result=$func_quote_portable_result + ;; + *) + printf -v func_quotefast_eval_result %q "$1" + ;; + esac + } + fi else func_quotefast_eval () { diff --git a/gl/build-aux/funclib.sh b/gl/build-aux/funclib.sh index 2c22db179..d95ac2d78 100644 --- a/gl/build-aux/funclib.sh +++ b/gl/build-aux/funclib.sh @@ -1,5 +1,5 @@ # Set a version string for this script. -scriptversion=2015-10-12.13; # UTC +scriptversion=2015-11-01.21; # UTC # General shell script boiler plate, and helper functions. # Written by Gary V. Vaughan, 2004 @@ -1106,10 +1106,27 @@ func_quote_portable () # Quote one ARG (internal). This is equivalent to 'func_quote_arg eval ARG', # but optimized for speed. Result is stored in $func_quotefast_eval. if test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then - func_quotefast_eval () - { - printf -v func_quotefast_eval_result %q "$1" - } + printf -v _GL_test_printf_tilde %q '~' + if test '\~' = "$_GL_test_printf_tilde"; then + func_quotefast_eval () + { + printf -v func_quotefast_eval_result %q "$1" + } + else + # Broken older Bash implementations. Make those faster too if possible. + func_quotefast_eval () + { + case $1 in + '~'*) + func_quote_portable false "$1" + func_quotefast_eval_result=$func_quote_portable_result + ;; + *) + printf -v func_quotefast_eval_result %q "$1" + ;; + esac + } + fi else func_quotefast_eval () { -- 2.47.3