Fix completion of directories containing files with uppercase extensions

Completion patterns are lowercased in make_completer and file names are
lowercased before being matched against them, but the names of files inside
a directory were passed to the matcher unchanged. A directory whose only
matching file was named something like B.CONF was therefore never offered as
a completion candidate for a *.conf pattern, while the same file named
b.conf worked.
This commit is contained in:
devangpratap 2026-09-16 00:43:53 -04:00
parent 1f20d43198
commit ebb41b83da
2 changed files with 16 additions and 1 deletions

View file

@ -156,7 +156,7 @@ func fname_based_completer(prefix, cwd string, is_match func(string) bool) []str
entries, err := os.ReadDir(entry.Abspath)
if err == nil {
for _, e := range entries {
if is_match(e.Name()) || is_dir_or_symlink_to_dir(e, filepath.Join(entry.Abspath, e.Name())) {
if is_match(strings.ToLower(e.Name())) || is_dir_or_symlink_to_dir(e, filepath.Join(entry.Abspath, e.Name())) {
ans = append(ans, entry.CompletionCandidate)
return
}

View file

@ -109,6 +109,21 @@ func TestCompleteFiles(t *testing.T) {
if len(c.Groups) != 1 || len(c.Groups[0].Matches) != 1 || c.Groups[0].Matches[0].Word != "slink/" {
t.Fatalf("Symlink to directory not completed by DirectoryCompleter: %#v", c.Groups)
}
// filenames inside a directory are matched case-insensitively against patterns
os.Mkdir(filepath.Join(tdir, "cdir"), 0700)
create("cdir", "B.CONF")
c = NewCompletions()
FnmatchCompleter("", CWD, "*.conf")(c, "c", 0)
found := false
for _, g := range c.Groups {
for _, m := range g.Matches {
found = found || m.Word == "cdir/"
}
}
if !found {
t.Fatalf("Directory containing only an uppercase extension match not completed by FnmatchCompleter: %#v", c.Groups)
}
}
func TestCompleteExecutables(t *testing.T) {