On 12/11/2011 10:48 PM, Raphaël Droz wrote:
> Just found the following bug:
> 
> $ var=$(id) find -<tab>
> bash: eval: line1: syntax error near unexpected « ) »
> bash: eval: line1: `local cmd=id)'

I managed to reproduce this, but only when the completion for "id" has
been already loaded.

> There is a bug from bash (completions from `id` instead of `find`) but
> bash-completion should be more robust to this.
> I didn't dug further but some entry points for variables may probably be
> sanitized (or at least quoted) a bit more.

The attached patch appears to fix it for _parse_help, without breaking
completions for commands from paths containing backslashed chars (e.g.
whitespace) or ones starting with a tilde.  _parse_usage is similarly
affected, but I'm not applying this to either because all this mess
starts to have a strong code smell on it.  I'm having a hard time
believing that it's really this hard to get stuff to work, are we doing
something wrong?  There must be a cleaner way.
diff --git a/bash_completion b/bash_completion
index ebebb8e..a787eb2 100644
--- a/bash_completion
+++ b/bash_completion
@@ -750,9 +750,9 @@ __parse_options()
 #
 _parse_help()
 {
-    eval local cmd=$1
+    eval local cmd=$( quote "$1" )
     local line
-    { case $cmd in -) cat ;; *) "$cmd" ${2:---help} 2>&1 ;; esac } \
+    { case $cmd in -) cat ;; *) "$( dequote "$cmd" )" ${2:---help} 2>&1 ;; 
esac } \
     | while read -r line; do
 
         [[ $line == *([ $'\t'])-* ]] || continue
_______________________________________________
Bash-completion-devel mailing list
Bash-completion-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel

Reply via email to