]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
tests: sanitise the libtool quote checking Autotests.
authorGary V. Vaughan <gary@gnu.org>
Sat, 6 Oct 2012 08:01:52 +0000 (15:01 +0700)
committerGary V. Vaughan <gary@gnu.org>
Sat, 6 Oct 2012 08:10:05 +0000 (15:10 +0700)
Carefully comment the maze of quoting and escaping needed to
pass through M4, $SHELL, and grep before regexp matching.
* tests/libtool.at (quote shell meta-characters in filenames):
Split backslash into a separate test group, because it needs
additional escaping.
Use grep consistently for the entire test group.
Use AT_CHECK rather than LT_AT_CHECK to avoid problems with
escaping literal $ correctly with LT_ESCAPE.
Use the correct number of backslashes for each sub-group.
Escape double-quote literals portably.
Reported by Peter Rosin.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
tests/libtool.at

index fafec379930be5a1023dd561d3630a8e7b98a211..4ab405cad868a53f23bca5905424d6dc1734dd7f 100755 (executable)
@@ -95,35 +95,53 @@ for mode in compile link install; do
     ;;
   esac
 
-  # Trivial.
-  LT_AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag:test" $postargs],
+
+  # Trivial...
+
+  AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag:test" $postargs],
           [0], [stdout])
   # We must not attempt to match $preargs in the output, because libtool
   # may modify them.  For example, on Cygwin, ``libtool --mode=link gcc -o
   # foo foo.o''  becomes ``gcc -o foo.exe foo.o''.
-  LT_AT_CHECK([$EGREP "$mode:.*$match_preflag$flag:test " stdout], [0], [ignore])
+  AT_CHECK([grep "$mode:.*$match_preflag$flag:test " stdout], [0], [ignore])
+
 
-  # Metacharacters that should be backslashified.
-  for mchar in \" \` \$ \\; do
-    LT_AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag$mchar:test$mchar" $postargs],
+  # Non-trivial...
+
+  # Backslash needs to be double-escaped: one escape is stripped as the shell
+  # collects arguments for grep (\\\\\\\\ => \\\\), and then another escape
+  # is stripped by grep itself (\\\\ => \\) before the resulting expression is
+  # matched (grepping for \\ matches \):
+  AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag\\:test\\" $postargs],
+          [0], [stdout])
+  # NOTE: we use "..."'"'"..." to insert a literal quote into the expression
+  #       because "...\"..." is not expanded consistently by all shells.
+  AT_CHECK([grep "$mode:.*$match_preflag"'"\?'"$flag\\\\\\\\:test\\\\\\\\"'"\? ' stdout],
+             [0], [ignore])
+
+  # Shell metacharacters that should be backslashified by libtool.
+  for mchar in \" \` \$; do
+    AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag$mchar:test$mchar" $postargs],
             [0], [stdout])
-    LT_AT_CHECK([$EGREP "$mode:.*$match_preflag\"?$flag\\\\\\$mchar:test\\\\\\$mchar\"? " stdout], [0], [ignore])
+    AT_CHECK([grep "$mode:.*$match_preflag"'"'"\?$flag\\\\$mchar:test\\\\$mchar"'"'"\? " stdout], [0], [ignore])
   done
 
-  # Metacharacters that should be double quoted, and need escaping for grep
+  # Shell metacharacters that should be double quoted by libtool, and need
+  # backslash escaping for input to grep.
   for mchar in "@<:@" "@:>@" "^" "*"; do
 
-    LT_AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag$mchar:test$mchar" $postargs],
+    AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag$mchar:test$mchar" $postargs],
             [0], [stdout])
-    LT_AT_CHECK([grep "$mode:.*$match_preflag\"$flag\\$mchar:test\\$mchar\" " stdout], [0], [ignore])
+    AT_CHECK([grep "$mode:.*$match_preflag\"$flag\\$mchar:test\\$mchar\" " stdout], [0], [ignore])
   done
 
-  # Metacharacters that should be double quoted, that are not special to grep.
+  # Metacharacters that should be double quoted by libtool, but which are
+  # not special to grep (NOTE: Some of these ARE special to $EGREP!!).
   for mchar in "~" "#" "&" "(" ")" "{" "}" "|" ";" "<" ">" "?" "'" " " "       "; do
 
-    LT_AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag$mchar:test$mchar" $postargs],
+    AT_CHECK([$LIBTOOL -n --mode=$mode $preargs $preflag"$flag$mchar:test$mchar" $postargs],
             [0], [stdout])
-    LT_AT_CHECK([grep "$mode:.*$match_preflag\"$flag$mchar:test$mchar\" " stdout], [0], [ignore])
+    AT_CHECK([grep "$mode:.*$match_preflag\"$flag$mchar:test$mchar\" " stdout], [0], [ignore])
   done
 done