tab completion fails when files have same prefix that ends in a quote/escapable-char

Bug #123665 reported by Yuki Izumi
34
This bug affects 4 people
Affects Status Importance Assigned to Milestone
bash-completion (Debian)
Fix Released
Unknown
bash-completion (Ubuntu)
Fix Released
Medium
Unassigned
Nominated for Karmic by Niels Kristian Bech Jensen

Bug Description

Binary package hint: bash

If two (or more) files have the same prefix that ends in a quote (double, single, take your pick), or some other escapable character (back-slash is my test case), but then something else, tab completion will fail! Here's how to reproduce:

1. Run: touch "1'1 1" "1'2 2"
2. Type: rm 1\'
3. Attempt to tab complete. bash will suggest the two files.
4. Give a hint by entering 1.
5. Attempt to tab complete again. bash is dumb-founded.

This occurs with single- and double-quotes, and backslashes -- but *not* with with spaces. Other cases are untested.

Checked as problematic on feisty and gutsy.

Yuki Izumi (kivikakk)
description: updated
Revision history for this message
Mika Fischer (zoop) wrote :

I can confirm this on a current hardy install.

It is a problem with bash, not bash-completion.

In the given test-case compgen -f does not work correctly:

$ touch "1'1 1" "1'2 2"
$ compgen -f 1\'
1'2 2
1'1 1
$ compgen -f 1\'1
$ echo $?
1

Changed in bash-completion:
status: New → Confirmed
Revision history for this message
Mika Fischer (zoop) wrote :

Another useful datapoint is that the submitter of #197183 claims that this worked in Dapper.

Revision history for this message
Niels Kristian Bech Jensen (nkbjensen) wrote :

I've just checked with a hardy alpha-6 desktop cd and it seems to be fixed there - at least the bug submitted as #197183.

Revision history for this message
Mika Fischer (zoop) wrote :

You're right. It seems to work when you're not using the bash-completion package. If you do however, then it's still broken.

I'm not sure yet wether it's a quoting problem or a genuine bug in bash:

mika@arthur:~/rrr(1)$ compgen -f "1\'"
1'2 2
1'1 1
mika@arthur:~/rrr$ compgen -f "1\'2"
mika@arthur:~/rrr(1)$ compgen -f "1\\'2"
mika@arthur:~/rrr(1)$ compgen -f "1\\\'2"
mika@arthur:~/rrr(1)$ compgen -f "1\\\\'2"
mika@arthur:~/rrr(1)$ compgen -f "1\\\\\'2"
1'2 2

Revision history for this message
Niels Kristian Bech Jensen (nkbjensen) wrote :

You're right. It doesn't work in Hardy when the bash-completion package is installed.

Revision history for this message
Mika Fischer (zoop) wrote :

The issue can be worked around in the bash_completion script. A fix will be included in the next upload.

Changed in bash:
assignee: nobody → zoop
status: Confirmed → In Progress
Revision history for this message
Mika Fischer (zoop) wrote :

I've prepared an updated package in my PPA which should fix the bug you reported.

If you're using hardy I'd appreciate it if you could test it and report whether your bug is indeed fixed and also whether you experienced any other regressions.

You can get the package from here:
http://launchpadlibrarian.net/13042048/bash-completion_20060301-3ubuntu2%7Eppa2_all.deb

To install it:
wget http://launchpadlibrarian.net/13042048/bash-completion_20060301-3ubuntu2%7Eppa2_all.deb
sudo dpkg -i dpkg -i bash-completion_20060301-3ubuntu2~ppa2_all.deb

To go back to the original package, do this:
sudo aptitude install bash-completion/hardy

If I don't get reports of regressions I'll try to get this version into hardy.

Thanks for your help!

Changed in bash-completion:
status: In Progress → Fix Committed
Revision history for this message
Niels Kristian Bech Jensen (nkbjensen) wrote :

Hi Mika.

You version of bash-completion fixes the problem for me. I have Yet to see any ill effects.

Regards,
Niels Kristian

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package bash-completion - 20060301-3ubuntu2

---------------
bash-completion (20060301-3ubuntu2) hardy; urgency=low

  * Bugfix release:
   - Fix _get_cword more
   - Fix _command function to correctly prune the command line (LP: #103395)
   - Remove newline from options pattern for dpkg (LP: #138312)
   - Start readline-quoting arguments to compgen (LP: #123665)
   - Save and restore -v shell option (LP: #205444)
   - Prevent glob expansion in _filedir function (LP: #194419)
   - Quote glob expression in tar completion function (LP: #194419)
   - Complete AAS/SSA files for mplayer -sub (LP: #151086)
   - Disable completion of postgresql users and databases (LP: #164772)
   - Use files from UserKnownHostsFile options in addition to standard ones
     (LP: #211180)

 -- Mika Fischer <email address hidden> Sat, 05 Apr 2008 16:09:34 +0200

Changed in bash-completion:
status: Fix Committed → Fix Released
Revision history for this message
dnquark (leo-alekseyev+launchpad) wrote :

I am seeing this bug on fresh Jaunty installations; bash_completion release 20080617.5 . Has the fix been reverted?.. Is there a way to get bash-completion with the fix in place?

Revision history for this message
Vanessa Dannenberg (vanessadannenberg) wrote :

This still exists exactly as originally reported, on Karmic, with the same solution (remove and purge the package, and restart any open terminals).

Revision history for this message
Niels Kristian Bech Jensen (nkbjensen) wrote :

I can confirm this bug on Karmic.

Changed in bash-completion (Ubuntu):
status: Fix Released → Confirmed
Revision history for this message
GTMS_OH (ericstockwell04) wrote :

I can confirm this as well in fully updated Karmic.

Revision history for this message
GTMS_OH (ericstockwell04) wrote :

This bug is still present in fully updated 10.04 64-bit Kubuntu. Any help on this is desperately needed.

It can be reproduced as follows:

$ mkdir "Apostrophe's a problem"
$ mkdir "Apostrophe's still a problem"

Now type:

$ cd Apostro

and tab-tab-tab to where it should autocomplete or offer options, but it only autocompletes to:

$ cd Apostrophe\'s\

and doesn't offer any suggestions. Furthermore, if you add on to where it should be able to autocomplete, like so:

$ cd Apostrophe\'s\ still

it does not autocomplete, even though there is only one possibility! Please take a look at this bug if possible, it is so annoying sometimes. Let me know if there is any other information I should provide, and I'll do what I can to help.

Revision history for this message
maxim (maximn) wrote : apport information

Architecture: i386
DistroRelease: Ubuntu 10.04
InstallationMedia: Ubuntu 10.04.1 LTS "Lucid Lynx" - Release i386 (20100721)
NonfreeKernelModules: nvidia
Package: bash-completion 1:1.1-3ubuntu2
PackageArchitecture: all
ProcEnviron:
 PATH=(custom, no user)
 LANG=en_US.utf8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.32-24.38-generic 2.6.32.15+drm33.5
Tags: lucid
Uname: Linux 2.6.32-24-generic i686
UserGroups:

tags: added: apport-collected
Revision history for this message
maxim (maximn) wrote : Dependencies.txt

apport information

Revision history for this message
maxim (maximn) wrote :

I can confirm this bug in Ubuntu 10.04.1 LTS. I appears to be related to the compgen built-in?

I found a related bug report which has been apparently applied? http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=560851

I'm not sure really. It's definitely still there though, very annoying.

Removing the package bash-completion allows it to function as expected again. (sudo apt-get remove bash-completion)

Revision history for this message
maxim (maximn) wrote :

I was mistaken in my previous post. Removing the bash-completion package doesn't fix it.

It works only in terminal sessions of the root user. I had selected the wrong window when performing the test.

Revision history for this message
maxim (maximn) wrote :

What does fix the issue is commenting out the following in the .bashrc in a given user's home directory:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

It's at the very end of the file and root's .bashrc has this section commented out which is why root isn't susceptible to it.

Mika Fischer (zoop)
Changed in bash-completion (Ubuntu):
assignee: Mika Fischer (zoop) → nobody
Revision history for this message
wojtas (dudwin) wrote :

Hi,
I have the same problem with bash for ex in for loop
bash: for i in $(cat <TAB><TAB>
desktop ~ $ for i in $(bash: unexpected EOF while looking for matching `)'
bash: syntax error: unexpected end of file

dpkg -l |grep bash
ii bash 4.3-7ubuntu1 amd64 GNU Bourne Again SHell
ii bash-completion 1:2.1-4 all programmable completion for the bash shell
ii command-not-found 0.3ubuntu12 all Suggest installation of packages in interactive bash sessions
ii inxi 1.8.4-1 all System info script for irc (forked from infobash by locsmith)

in attachemnet I add the set -x

in bash
desktop ~ # dpkg -l |grep bash
ii bash 4.2-2ubuntu2 GNU Bourne Again SHell
ii bash-completion 1:1.3-1ubuntu8 programmable completion for the bash shell

I didn;t notice that problem

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

The fix for bug 1387057 (correctly quoting $quoted) also fixes this.

$ compgen -f "1\'2"
1'2 2

@wojtas: completion inside $(command substitutions) is a separate bug. Fixing the quoting bug didn't solve that. I see you already commented in bug 1312243, which is what you're seeing.

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

Actually, this isn't broken even with Trusty's unchanged file. Unless I'm missing something, the OP's testcase works fine on Trusty, so marking this fix-released

Changed in bash-completion (Ubuntu):
status: Confirmed → Fix Released
Mathew Hodson (mhodson)
tags: added: testcase
Changed in bash-completion (Ubuntu):
importance: Undecided → Medium
Changed in bash-completion (Debian):
status: Unknown → Confirmed
Changed in bash-completion (Debian):
status: Confirmed → Fix Released
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.