bash-completion not working properly with directories with spaces in them when using some commands

Bug #1894352 reported by Jason
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash-completion (Ubuntu)
New
Undecided
Unassigned

Bug Description

Good evening!

Unfortunately, I need to report an issue with Ununtu 20.04's bash-completion (bash_completion version 2.10). It can't properly expand directories with spaces when there are multiple options when using some commands. Here is an example:

$ mkdir -p "p00p/p00p 1"
$ mkdir -p "p00p/p00p 2"
$ ls -d p00p/p00p\ 1 p00p/p00p\ 2
'p00p/p00p 1' 'p00p/p00p 2'
$ ls p00p/p0<tab><tab>
p00p 1/ p00p 2/
$ ls p00p/p0<tab>1<tab> # <-- works: yields the expanded command: ls p00p/p00p\ 1/
$ wine p00p/p0<tab><tab> # <-- does NOT work: fails to show possible expansions: p00p 1/ p00p 2/
$ wine p00p/p0<tab>1<tab> # <-- does NOT work: fails to expand to: wine p00p/p00p\ 1/

I temporarily fixed it by patching the portion of bash_completion which invokes plusdirs with the version from my raspberry pi OS (bash_completion version 2.8). Here's the patch that fixes it:

--- /usr/share/bash-completion/bash_completion 2020-09-04 20:39:18.453560935 -0700
+++ /home/xxx/bash_completion 2020-09-04 20:39:13.625394958 -0700
@@ -563,37 +559,28 @@
     _tilde "$cur" || return

     local -a toks
- local reset
+ local x reset

- if [[ "$1" == -d ]]; then
         reset=$(shopt -po noglob); set -o noglob
         toks=( $(compgen -d -- "$cur") )
- IFS=' '; $reset; IFS=$'\n'
- else
+ eval $reset
+
+ if [[ "$1" != -d ]]; then
         local quoted
         _quote_readline_by_ref "$cur" quoted

         # Munge xspec to contain uppercase version too
         # http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
- local xspec=${1:+"!*.@($1|${1^^})"} plusdirs=()
-
- # Use plusdirs to get dir completions if we have a xspec; if we don't,
- # there's no need, dirs come along with other completions. Don't use
- # plusdirs quite yet if fallback is in use though, in order to not ruin
- # the fallback condition with the "plus" dirs.
- local opts=( -f -X "$xspec" )
- [[ $xspec ]] && plusdirs=(-o plusdirs)
- [[ ${COMP_FILEDIR_FALLBACK-} ]] || opts+=( "${plusdirs[@]}" )
-
+ local xspec=${1:+"!*.@($1|${1^^})"}
         reset=$(shopt -po noglob); set -o noglob
- toks+=( $(compgen "${opts[@]}" -- $quoted) )
- IFS=' '; $reset; IFS=$'\n'
+ toks+=( $( compgen -f -X "$xspec" -- $quoted ) )
+ eval $reset

         # Try without filter if it failed to produce anything and configured to
         [[ -n ${COMP_FILEDIR_FALLBACK:-} && -n "$1" && ${#toks[@]} -lt 1 ]] && {
             reset=$(shopt -po noglob); set -o noglob
- toks+=( $(compgen -f "${plusdirs[@]}" -- $quoted) )
- IFS=' '; $reset; IFS=$'\n'
+ toks+=( $( compgen -f -- $quoted ) )
+ eval $reset
         }
     fi

<EOF>

Unfortunately, to apply the patch with patch -p0, I had to type in the name of the file to patch because the patch I saved was only a subset of the patch produced by "diff -u -w" and my diff-fu isn't good enough to know how to fix it. But, providing the name of the file to be patched when prompted (/usr/share/bash-completion/bash_completion) made it work and after I sourced the new file the issue was fixed.

Thus, this appears to be a regression of sorts but my bash programming skills aren't good enough to fix it myself while ensuring that any functionality provided by the portions that I replaced isn't lost.

Thank you!

Very sincerely,

Jason A. Pfeil

ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: bash-completion 1:2.10-1ubuntu1 [modified: usr/share/bash-completion/bash_completion]
ProcVersionSignature: Ubuntu 5.4.0-45.49-generic 5.4.55
Uname: Linux 5.4.0-45-generic x86_64
NonfreeKernelModules: nvidia_modeset nvidia
ApportVersion: 2.20.11-0ubuntu27.8
Architecture: amd64
CasperMD5CheckResult: skip
CurrentDesktop: ubuntu:GNOME
Date: Fri Sep 4 20:50:10 2020
Dependencies:

EcryptfsInUse: Yes
InstallationDate: Installed on 2020-08-29 (7 days ago)
InstallationMedia: Ubuntu 20.04.1 LTS "Focal Fossa" - Release amd64 (20200731)
PackageArchitecture: all
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: bash-completion
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Jason (jason-pfeil) wrote :
Revision history for this message
Jason (jason-pfeil) wrote :

In case the copy and paste of the text of the patch isn't usable, I have attached the file to this bug to make it easier to evaluate.

Thank you!

Very sincerely,

Jason A. Pfeil

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "File containing the patch that corrects the regression" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
tags: added: rls-ff-incoming
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Have you experienced this with upstream bash-completion? https://github.com/scop/bash-completion

Could you submit your patch there? Cause this issue is not Ubuntu specific, is it? And thus should be fixed for everyone?

tags: added: rls-ff-notfixing
removed: rls-ff-incoming
Revision history for this message
Jason (jason-pfeil) wrote :

Dimitri John Ledkov (xnox):

After checking the version at that upstream package it is also b0rked so it seems like it's not ubuntu-specific. I'll resubmit it there.

Thank you!

Very sincerely,

Jason A. Pfeil

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

Other bug subscribers

Remote bug watches

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