On Sun, Jul 02, 2017 at 10:46:21PM +0200, Anton Lindqvist wrote:
Hi,
On Fri, Jun 30, 2017 at 09:50:12PM -0700, Ilya Kaliman wrote:
Hi!
The tab-autocomplete does not seem to work for some strings in ksh.
How to reproduce:
mkdir "a a" "(bbb)" "(c c)"
cd a\ a && mkdir abc{1,2,3} && cd ..
cd \(bbb\) && mkdir abc{1,2,3} && cd ..
cd \(c\ c\) && mkdir abc{1,2,3} && cd ..
type "cd a\ a/" hit tab -> auto-completes to abc, offers abc1 abc2 abc3
type "cd \(bbb\)/" hit tab -> auto-completes to abc, offers abc1 abc2 abc3
type "cd \(c\ c\)/" hit tab -> does not autocomplete; expected - same
as previous.
Nice catch. As I see it, the bug you're seeing happens inside
do_complete() while comparing the length of the input buffer and the
results from the completion. Since the completions are passed through
expand() causing escaped characters to be unescaped to their literal
form while the input buffer remains escaped. You managed to find the
perfect set of input causing the condition to when a completion
succeeded to be invalidated:
olen = strlen("\(c\ c\)/") = 9;
nlen = strlen("(c c)/abc") = 9;
Since `olen == nlen` no completion is performed. Please try out the diff
below in which slashes are discarded when comparing the length. I don't
know if any other character should be discarded as well, if true then it
might be worth passing the input buffer through ksh's own lexer and
parser in order to properly handle special characters, just like in
x_file_glob().
So I tried reproducing this in both vi and emacs mode but with no avail,
here's the typescript showing successfull auto-completion for directory
names in "(c c)" (^U is used to clear the line):
Script started on Sun Jul 2 23:24:06 2017
$ mkdir -p "(c c)"/abc{1,2,3}
$ cd \(c\ c\)/abc
abc1/ abc2/ abc3/
$ cd \(c\ c\)/abc
$
$ set -o emacs
$ cd \(c\ c\)/abc
abc1/ abc2/ abc3/
$ cd \(c\ c\)/abc
$ ^D
Script done on Sun Jul 2 23:25:13 2017
What are you guys doing differently that triggers this bug?