Skip to content

bash completion mangles file names containing newline characters #704

Open
@idallen

Description

@idallen

Describe the bug

BASH completion cannot correctly handle file names containing newline characters.
The file names are split apart at the newlines, making them useless.

To reproduce

        # First, get a shell with no completion loaded and show it working:     
        $ bash --norc
        bash-5.0$ ls -b
        one\ntwo\nthree\nfour\nfive\nsix
        bash-5.0$ xxx <TAB>'one
        two
        three
        four
        five
        six'
        bash-5.0$ touch foo
        bash-5.0$ xxx <TAB>
        foo                               one^Jtwo^Jthree^Jfour^Jfive^Jsix
        bash-5.0$ xxx o<TAB>'one
        two
        three
        four
        five
        six'

        # Now, load the completion scripts and watch it break:                  
        bash-5.0$ source /usr/share/bash-completion/bash_completion
        bash-5.0$ ls -b
        foo  one\ntwo\nthree\nfour\nfive\nsix
        bash-5.0$ xxx <TAB>
        five   foo    four   one    six    three  two
        bash-5.0$ xxx o<TAB>
        five   four   one    six    three  two
        # The last two completions are garbage.                                 
        # The file name is being split on newlines. 

Expected behavior

See above, before the loading of /usr/share/bash-completion/bash_completion

Versions (please complete the following information)

  • [GNU/linux/Ubuntu 20.04.4 LTS] Operating system name/distribution and version:
  • [5.0.17(1)-release] bash version, echo "$BASH_VERSION":
  • [2.10] bash-completion version, (IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"):

Additional context

I used the nonexistent command name xxx so as not to invoke any helper completion scripts.

Debug trace

See attached typescript.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions