Bug 1171396 - tab auto-completion is not working with objects containing escaped characters
Summary: tab auto-completion is not working with objects containing escaped characters
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: bash-completion
Version: 21
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Ville Skyttä
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 1171496 1179227 1202078 1215362 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-12-06 10:50 UTC by RudraB
Modified: 2015-05-26 03:51 UTC (History)
26 users (show)

Fixed In Version: bash-completion-2.1-7.20150513git1950590.fc22
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-05-26 03:51:13 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Screencast for the behavior reported in this bug (115.43 KB, application/octet-stream)
2014-12-06 10:50 UTC, RudraB
no flags Details
bash-completition _cd patch (384 bytes, patch)
2015-01-29 17:24 UTC, Michael Cronenworth
no flags Details | Diff
bash-completition _cd patch 2 (698 bytes, patch)
2015-01-29 18:33 UTC, Michael Cronenworth
no flags Details | Diff
bash-completion patch v3 (738 bytes, patch)
2015-02-17 16:36 UTC, Michael Cronenworth
no flags Details | Diff

Description RudraB 2014-12-06 10:50:15 UTC
Created attachment 965414 [details]
Screencast for the behavior reported in this bug

Description of problem:
If I have 2 dir, say Axyz and "A B C", I cant do "cd A\ <tab>" or even "A\ B<tab>"to reach "A B C" ...the tab completion is not working. 

If there is no other directory starting with "A", its working fine.

Version-Release number of selected component (if applicable):
3.14

How reproducible:
Always

Steps to Reproduce:
1. Have 2 or more directory starting with same initial (A here) and one of them having space in its name("A B C")
2. in gnome terminal, press A\ B<tab>
3.

Actual results:
Nothing happenning

Expected results:
bash autocomplete should take you to "A\ B\ C" dir


Additional info:
I have attached a screencast to show this. Unfortunately, I have no way to capture keys, so, you have to trust me that I am really pressing <tab>

Comment 1 Matthias Clasen 2014-12-08 14:56:09 UTC
this has nothing to do with gnome-terminal. completion is entirely up the shell

Comment 2 Ondrej Oprala 2014-12-09 09:32:50 UTC
Hi, thanks for the report. Could you please specify the versions of your bash and bash-completion packages?
Thanks

Comment 3 Ralf Ertzinger 2015-01-12 21:21:04 UTC
bash-4.3.33-1.fc21.x86_64
bash-completion-2.1-6.20141110git52d8316.fc21.noarch


There's a long-ish discussion of this on the debian bugtracker:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=740971

Comment 4 Ondrej Oprala 2015-01-23 16:02:53 UTC
*** Bug 1171496 has been marked as a duplicate of this bug. ***

Comment 5 RudraB 2015-01-26 16:07:04 UTC
Today I checked a bit more. This seems to be, as from debian's bug suggest by Ralf, its due to bash-completion.

From bash-completion trouble-shooting, i did:
$set -v
$ls A\words=("${@:3:2}")
cword="$3"
cur="$3"
cur="$3"
cword="$3"
prev="$3"
words=("${@:3:2}")

Comment 6 Michael Cronenworth 2015-01-29 15:52:28 UTC
Bash 4.2 tab works. Bash 4.3 tab is broken.

Native auto-completion (Alt+/) works on both versions.

Comment 7 Michael Cronenworth 2015-01-29 17:08:17 UTC
As noted in comment 5, this is a bug in bash-completion.

Comment 8 Michael Cronenworth 2015-01-29 17:24:06 UTC
Created attachment 985686 [details]
bash-completition _cd patch

This is fixed for me by using the attached patch. The problem may be in another area, but I'm not very familiar with bash-completion.

Comment 9 Michael Cronenworth 2015-01-29 18:33:21 UTC
Created attachment 985710 [details]
bash-completition _cd patch 2

The same problem happens with mkdir and rmdir since it goes through the same function option '-d'.

Comment 10 RudraB 2015-01-30 00:06:40 UTC
I can confirm that removing "-d" from line 1616 solves the problem, as suggested by Michael

Comment 11 Ville Skyttä 2015-02-01 12:18:46 UTC
Replacing _filedir -d with plain _filedir is wrong because then we will end up offering filenames as completions where we want dir names only (that's what the -d there signifies).

Additionally, the patch is far from complete.
# grep -R "_filedir -d" /usr/share/bash-completion | wc -l
229
(that's counting symlinks too, but anyway)

This needs to be fixed by getting _filedir -d working properly with bash 4.3.

Comment 12 Michael Cronenworth 2015-02-01 19:53:38 UTC
I never suggested my patch was complete. I agree the '-d' option must be fixed, or if may end up being the wrong option for these few cases.

Comment 13 Michael Cronenworth 2015-02-17 16:36:28 UTC
Created attachment 992781 [details]
bash-completion patch v3

The problem is the _quote_readline_by_ref function. It escapes any escapes because it calls printf with %q. The double-escaped string is passed to compgen -d and the "-d" option to compgen does not match directories with escapes like the "-f" option does.

If I add a eval line to undo any escapes before calling the _quote_readline_by_ref function tab completion works as expected. This patch should be a possible, proper fix.

Comment 14 markzzzsmith 2015-02-19 06:30:08 UTC
So it might be a bug in bash-4.3, however if I comment out the inclusion of /etc/bashrc from my .bashrc file, bash-4.3 works as expected. So something /etc/bashrc is 'enabling' the bug.

(keypresses enclosed in []s)

bash-4.3$ mkdir Axyz
bash-4.3$ mkdir "A B C"
bash-4.3$ cd A[tab][tab]
A B C/ Axyz/  
bash-4.3$ cd A[\][space][tab]\ B\ C/[enter]
bash-4.3$ pwd
/tmp/A B C
bash-4.3$

Comment 15 markzzzsmith 2015-02-19 06:33:13 UTC
i.e., 

# .bashrc

# Source global definitions
#if [ -f /etc/bashrc ]; then
#	. /etc/bashrc
#fi

Comment 16 Michael Cronenworth 2015-02-19 07:35:07 UTC
It is not a bash bug. Your bashrc enables bash-completion and during that process it disables bash's native auto-completion and enables it's own auto-completion.

See bash-completion patch v3 if you want to fix your system.

Comment 17 Ville Skyttä 2015-02-19 20:20:46 UTC
Thanks a bunch for looking into this! I do however still have some reservations about this patch:

What we have reported is a problem with filedir -d, however the patch changes things also for non -d _filedir completions and I'd rather not go there at all unless we do have some evidence that there is a bug to be fixed in those completions as well.

Second, we already have the unquoted version of $cur around, no need to unquote it again. So the patch would simplify to this:

diff --git a/bash_completion b/bash_completion
index 24b6aa6..6eca58c 100644
--- a/bash_completion
+++ b/bash_completion
@@ -570,3 +570,3 @@ _filedir()
     _quote_readline_by_ref "$cur" quoted
-    x=$( compgen -d -- "$quoted" ) &&
+    x=$( compgen -d -- "$cur" ) &&
     while read -r tmp; do

This seems to fix the reported problem and does not cause any new test suite failures with bash 4.3.33 nor any regressions with bash 4.2.53 as far as I see, so I've pushed this along with a test case upstream.

http://anonscm.debian.org/cgit/bash-completion/bash-completion.git/commit/?id=d2920b7e79e5f347fed064b2a5aa952ef200e615

Comment 18 Michael Cronenworth 2015-02-19 21:33:05 UTC
It would not have affected other usage as compgen -f didn't care about double escapes, but I just encountered a failure when using escape-required characters other than a space. The upstream patch looks complete.

Thanks.

Comment 19 Ville Skyttä 2015-02-20 11:01:00 UTC
It's maybe not quite as simple as that, I mean the escaping/quoting mess must be there for a reason. The reason might be related to some older versions of bash we no longer support (for example the _filedir commentary is clearly outdated) but this is such a can of worms that I don't want to touch it unless something's demonstrably broken and a related test case can be added for it.

Comment 20 Ville Skyttä 2015-03-15 11:55:59 UTC
*** Bug 1179227 has been marked as a duplicate of this bug. ***

Comment 21 Ville Skyttä 2015-03-15 12:05:53 UTC
*** Bug 1202078 has been marked as a duplicate of this bug. ***

Comment 22 Ville Skyttä 2015-04-27 07:25:35 UTC
*** Bug 1215362 has been marked as a duplicate of this bug. ***

Comment 23 Michael Cronenworth 2015-04-27 13:43:57 UTC
Ville, will we see a package update so you can stop closing duplicates?

Comment 24 Ville Skyttä 2015-04-27 14:00:47 UTC
Yes. I'd rather do it via a new upstream release which I've been asking for for quite some time now, but it hasn't happened yet.

Comment 25 Fedora Update System 2015-05-13 15:13:11 UTC
bash-completion-2.1-6.20150513git1950590.fc22 has been submitted as an update for Fedora 22.
https://admin.fedoraproject.org/updates/bash-completion-2.1-6.20150513git1950590.fc22

Comment 26 Devin Henderson 2015-05-13 15:38:46 UTC
Still seeing the bug with bash-completion-2.1-6.20150513git1950590.fc22

mkdir "A B C"
cd A\ [tab][tab]

nothing happens.

Comment 27 Ville Skyttä 2015-05-14 10:38:02 UTC
GAH, the package forgot to apply the fix /etc/bash_completion.d/redefine_filedir in addition to the main location. redefine_filedir exists only in this package, not in an upstream setup such as mine which is why it worked for me and in upstream test suite.

Updated update, go try it out and leave karma how it looks now:
https://admin.fedoraproject.org/updates/bash-completion-2.1-7.20150513git1950590.fc22

Comment 28 Devin Henderson 2015-05-14 19:02:48 UTC
bash-completion-2.1-7.20150513git1950590.fc22 works! I'm not seeing the bug any more.

Thanks!

Comment 29 Michael Cronenworth 2015-05-14 21:11:11 UTC
Could you also push a F21 update? That's what the original report was from. Thanks, Ville.

Comment 30 Fedora Update System 2015-05-14 22:22:02 UTC
Package bash-completion-2.1-7.20150513git1950590.fc22:
* should fix your issue,
* was pushed to the Fedora 22 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing bash-completion-2.1-7.20150513git1950590.fc22'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-8232/bash-completion-2.1-7.20150513git1950590.fc22
then log in and leave karma (feedback).

Comment 31 Fedora Update System 2015-05-15 13:25:01 UTC
bash-completion-2.1-7.20150513git1950590.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/bash-completion-2.1-7.20150513git1950590.fc21

Comment 32 Fedora Update System 2015-05-19 16:17:52 UTC
bash-completion-2.1-7.20150513git1950590.fc21 has been pushed to the Fedora 21 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 33 Fedora Update System 2015-05-26 03:51:13 UTC
bash-completion-2.1-7.20150513git1950590.fc22 has been pushed to the Fedora 22 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.