helpThe GNU Bourne-Again SHell - Support: sr #109251, Bash completion interaction with...

 
 

sr #109251: Bash completion interaction with quotes

Submitted by:  None
Submitted on:  Wed 08 Feb 2017 03:47:24 PM UTC  
 
Category: NonePriority: 5 - Normal
Severity: 3 - NormalStatus: In Progress
Privacy: PublicAssigned to: None
Originator Email: -unavailable-Open/Closed: Open
Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Sun 12 Feb 2017 12:06:20 AM UTC, comment #1:

Well, the issue is (again) mismatched expectations. The bash
documentation says that when computing COMP_WORDS, the line is
broken into words the way readline does it. You're expecting it to happen the way bash does it with a non-default $IFS.

I'm not opposed to changing this, but I will have to look at how
it might change whatever the existing versions of bash_completion
expect.

Chet Ramey <chet>
Project Administrator
Wed 08 Feb 2017 03:47:24 PM UTC, original submission:

There is a strange interaction between the completion and the use of single or double quotes in the command line. More precisely, when the quote is preceded by a delimiter, it is treated also as a common delimiter, ignoring that it has the distinctive feature that it opens a string.

This happens quite often when trying to complete commands such as:
`my_command --first-option="text_with_possible_spaces" --second-op<TAB>`

What happens is that COMP_WORDS contains ([my_command] [--first-option] [="] [text_with_possible_spaces" --second-op]), where the brackets delimit each word.

The function "split_at_words" in subst.c seems responsible for this behavior (especially lines 2299-2310 in Bash-4.4 patch 12). When a delimiter (here "=") is encountered, it tries to add as many consecutive delimiters as it can. And since the quotes are in COMP_WORDBREAKS, they are added to this word. And when the completion sees the second quote, it treats it as the opening of a string (since the first quote was ignored), creating the strange word [text_with_possible_spaces" --second-op], that obviously will not give interesting completions.

A solution could be to remove the quotes (' and ") from variable "d2", or to treat them in a specific way in lines 2299-2310. But probably there are other constraints that I am not aware of.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by chet (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 12 Feb 2017 12:06:20 AM UTCchetStatusNone=>In Progress

    Back to the top


    Powered by Savane 3.1-cleanup1