2 # quote.test - make sure that shell metacharacters do not blow up libtool
4 # Copyright (C) 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
5 # Written by Gary V. Vaughan, 2003
7 # This file is part of GNU Libtool.
9 # GNU Libtool is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
14 # GNU Libtool is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU Libtool; see the file COPYING. If not, a copy
21 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
22 # or obtained by writing to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 . tests/defs || exit 1
28 # Do the torture test.
35 func_get_config "SHELL" "$LIBTOOL --config"
36 exec $SHELL "$0" --no-reexec ${1+"$@"}
40 func_get_config "ECHO wl" "$LIBTOOL --config"
42 for mode in compile link install; do
45 # Unfortunately, without an array data type, it is nearly impossible
46 # to protect libtool from metacharacters in filenames. So, we just
47 # try metacharacters in the options it needs to pass to other programs.
49 # preargs and postargs need to go through libtool unmodified.
60 preargs="$CC -o hell -g -O"
72 postargs="hell /usr/local/bin/hell"
77 echo "= trying: no quoting"
78 result=`$LIBTOOL -n --mode=$mode $preargs ${preflag}"${flag}test" $postargs` || status=$EXIT_FAILURE
79 # We used to have the contents of $match in the case statement,
80 # without an intermediate variable, but it would fail on at least
81 # Solaris' and HP-UX's /bin/sh. Ugh!
82 # We must not attempt to match $preargs in the output, because libtool
83 # may modify them. For example, on Cygwin, ``libtool --mode=link gcc -o
84 # foo foo.o'' becomes ``gcc -o foo.exe foo.o''.
85 match="${match_preflag}${flag}test "
88 $ECHO "= passed: $result"
91 $ECHO "= failed: $result"
96 # Metacharacters that should be backslashified.
97 for mchar in \\ \" \` \$; do
98 $ECHO "= trying: \\$mchar quoting"
99 result=`$LIBTOOL -n --mode=$mode $preargs ${preflag}"${flag}${mchar}test${mchar}" $postargs` || status=$EXIT_FAILURE
100 match="${match_preflag}${flag}\\${mchar}test\\${mchar} "
101 alt_match="${match_preflag}\"${flag}\\${mchar}test\\${mchar}\" "
104 $ECHO "= passed: $result"
107 $ECHO "= passed (harmless ksh bug): $result"
110 $ECHO "= failed: $result"
116 # Metacharacters that should be double quoted.
117 for mchar in "[" "]" "~" "#" "^" "&" "*" "(" ")" "{" "}" "|" ";" "<" ">" "?" \
120 $ECHO "= trying: \"$mchar\" quoting"
121 result=`$LIBTOOL -n --mode=$mode $preargs ${preflag}"${flag}${mchar}test${mchar}" $postargs` || status=$EXIT_FAILURE
122 match="${match_preflag}\"${flag}${mchar}test${mchar}\" "
125 $ECHO "= passed: $result"
128 $ECHO "= failed: $result"