wildcard incorrect completion

Bug #1387057 reported by Rolf Leggewie
36
This bug affects 7 people
Affects Status Importance Assigned to Milestone
bash-completion (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

steps to reproduce (verified on trusty)

$ touch /tmp/file01.txt;touch /tmp/file11.txt
$ file /tmp/fileTAB
file01.txt file02.txt
$ file /tmp/file*TAB

the last command will then incorrectly complete to

$ file /tmp/file01.txt

Tags: patch trusty
Revision history for this message
Peter Cordes (peter-cordes) wrote :

The problem is a lack of quoting in /usr/share/bash_completion/bash_completion.

set -x revealed where the problem happens: in a compgen -X -f. $quoted is used without quotes, so it expands, and you get the first of however many glob expansions.

 There are two unquoted uses of $quoted in _filedir(). Fixing them fixed my tab-expanding-globs problem.

 Don't forget to apply the fix for bug 1390061, too. Another case of lack of quoting leading to code that doesn't do what was intended.

Changed in bash-completion (Ubuntu):
status: New → Confirmed
tags: added: patch
Revision history for this message
Peter Cordes (peter-cordes) wrote :

submitted upstream as
https://alioth.debian.org/tracker/index.php?func=detail&aid=314891&group_id=100114&atid=413095

bug 1390061 is fixed upstream, as a side-effect of reworking the relevant code.

Revision history for this message
Rolf Leggewie (r0lf) wrote :

Thanks, Peter.

The problem is still the same at least for vivid. I can't see the relevant upstream bug at the moment which is only visible to logged in members. If there is something to backport, we should.

Mathew Hodson (mhodson)
Changed in bash-completion (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Dabe Murphy (dabe-c) wrote :

In addition to the unquoted "$quoted" that @peter-cordes mentioned, there's another bug in the _filedir() function:

    --- /usr/share/bash-completion/bash_completion--OLD 2015-08-19 19:58:22.734667377 -0500
    +++ /usr/share/bash-completion/bash_completion 2016-01-05 15:56:50.442988910 -0500
    @@ -604,6 +604,8 @@
             # 2>/dev/null for direct invocation, e.g. in the _filedir unit test
             compopt -o filenames 2>/dev/null
             COMPREPLY+=( "${toks[@]}" )
    + else
    + compopt -o bashdefault 2>/dev/null
         fi
     } # _filedir()

This lets you eat your cake and have it, too: you can keep your "shopt -s progcmp" bash_completion AND if that doesn't find a match, it will fall back to using bash's default glob-handling.

(This also solves Bug 1361404)

Revision history for this message
Tv (tv42) wrote :

This bug seems to affect 17.10 too. 3+ years and going on strong.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.