From: Gary V. Vaughan Date: Sat, 6 Oct 2012 08:01:52 +0000 (+0700) Subject: tests: sanitise the libtool quote checking Autotests. X-Git-Tag: v2.4.2.418~140 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5962e9ab32b54d37d5cece3dea56cdd3fcf1f914;p=thirdparty%2Flibtool.git tests: sanitise the libtool quote checking Autotests. 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 --- diff --git a/tests/libtool.at b/tests/libtool.at index fafec3799..4ab405cad 100755 --- a/tests/libtool.at +++ b/tests/libtool.at @@ -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