Package: bash-completion
Version: 1:2.11-6
Severity: normal
X-Debbugs-Cc: bugs.debian....@wongs.net

Dear Maintainer,

Currently, if a file with '$' (dollar sign) in it exists, Bash
completion will quote a leading '~' (tilde) and not quote the tilde.

To reproduce (where '^I' represents hitting the Tab key):

    $ touch ~/'APL$FONT'

    $ echo ~/APL^I
   -> echo \~/APL$FONT

As you can see, the wrong symbol was quoted. Even worse, if the $ had
been quoted using '\' (backslash), the backslash will be removed.

    $ echo ~/APL\$FONT^I
   -> echo \~/APL$FONT

Note that using $HOME fails in the same ways. It does not add a
backslash and will remove one that the user types.

    $ echo $HOME/APL^I
   -> echo $HOME/APL$FONT
   
    $ echo $HOME/APL\$FONT^I
   -> echo $HOME/APL$FONT
   
However, replacing the ~ or $HOME with the full path does work as
it should. (Mostly. See below.)

    $ echo /home/ben/APL^I
   -> echo /home/ben/APL\$FONT

I believe the following is not relevant for this bug, but I include it
for completeness.

----------------------------------------------------------------------
Trying to use a single tick (') to quote the dollar sign does not work
and completion fails with no possibilities. However, that appears to
be a general lack in bash_completion and probably should be its own
bug.

    $ echo ~/'APL^I^I
   -> echo ~/'APL

    $ echo $HOME/'APL^I^I
   -> echo $HOME/'APL

    $ echo /home/ben/'APL^I^I
   -> echo /home/ben/'APL

Single tick does work if at the beginning of a fully specified
pathname, but of course that doesn't help for ~ or $HOME.

    $ echo '/home/ben/APL^I
   -> echo '/home/ben/APL$FONT'
   
----------------------------------------------------------------------

By the way, I was a bit confounded debugging this. I traced through
all the functions in /usr/share/bash-completion/bash_completion and it
seems like it is correctly detecting the leading '~' and makes an
effort to avoid quoting it.

I even tried `shopt -u progcomp` and was still experiencing the bug!

The only way I could stop it was to disable tab completion completely
in Bash using `bind "set disable-completion on"`. Could it be a bug in
readline? Whatever it is, there is deeper magic going on here than I
understand.


-- System Information:
Debian Release: 12.0
  APT prefers stable-security
  APT policy: (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.1.0-10-amd64 (SMP w/8 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- no debconf information

Reply via email to