Subject: Re: SSH hostname completion with common suffix and globcomplete inserts characters
From: Bart Schaefer <[email-masked]>
To: [email-masked]
Date: Wed, 17 Aug 2016 15:36:18 -0700
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Aug 17,  9:16pm, Daniel Hahler wrote:
}
} % echo "Host test-05827d88.foo.bar test-6cae9ce0.foo.bar" > ssh_config
} % setopt globcomplete
} % ssh -F ssh_config test-<TAB>
} % ssh -F ssh_config test-|.foo.bar
} % ssh -F ssh_config test-|BR.foo.bar

I compared _complete_debug output for the two cases and there's no
significant difference until the value of compstate[unambiguous] is
displayed near the end, so this looks like an off-by-one error in
the internals.

Cursory examination seems to point to implicit addition/removal of
the "*" pattern at the cursor position when doing globcomplete.  If
instead one explicitly completes

% ssh -F ssh_config test-*<TAB>

then a listing of possible matches appears and the update of the line
is correct.

} The characters being inserted seem to come from the "bar".

I think the characters being inserted are just stack (or heap) garbage;
it may coincidentally be garbage derived from trying a case replacement,
but I don't think that's directly related.

Places to look more closely seem to be computil.c:cfp_opt_pats() and
compcore.c:addmatches(), look for comppatmatch.  For example, most of
cfp_opt_pats() is skipped if the prefix or suffix already contains a
pattern (as in "test-*") but is active if the prefix has no pattern
and comppatmatch is non-empty (as is the case for globcomplete).