From 8d7662335e902191960aacbc5ba818b81b9632ab Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sat, 29 Oct 2022 10:24:03 +0200 Subject: [PATCH] function: Don't list empty function names and directories --- src/function.cpp | 10 +++++++--- tests/checks/function.fish | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/function.cpp b/src/function.cpp index effa8998f..b64d57bc0 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -127,9 +127,13 @@ static void autoload_names(std::unordered_set &names, bool get_hidden) if (!get_hidden && fn[0] == L'_') continue; suffix = std::wcsrchr(fn, L'.'); - if (suffix && (std::wcscmp(suffix, L".fish") == 0)) { - wcstring name(fn, suffix - fn); - names.insert(name); + // We need a ".fish" *suffix*, it can't be the entire name. + if (suffix && suffix != fn && (std::wcscmp(suffix, L".fish") == 0)) { + // Also ignore directories. + if (!entry->is_dir()) { + wcstring name(fn, suffix - fn); + names.insert(name); + } } } } diff --git a/tests/checks/function.fish b/tests/checks/function.fish index 161c89503..fd926c4cb 100644 --- a/tests/checks/function.fish +++ b/tests/checks/function.fish @@ -114,4 +114,38 @@ end functions -q; or echo False #CHECK: False + +# See that we don't count a file with an empty function name, +# or directories +set -l tmpdir (mktemp -d) +touch $tmpdir/.fish +mkdir $tmpdir/directory.fish +touch $tmpdir/actual_function.fish + +begin + set -l fish_function_path $tmpdir + functions +end +# CHECK: actual_function + +# these are functions defined either in this file, +# or eagerly in share/config.fish. +# I don't know of a way to ignore just them. +# +# CHECK: bg +# CHECK: disown +# CHECK: fg +# CHECK: fish_command_not_found +# CHECK: fish_sigtrap_handler +# CHECK: frob +# CHECK: kill +# CHECK: name1 +# CHECK: name1a +# CHECK: name3 +# CHECK: name3a +# CHECK: t +# CHECK: wait + +rm -r $tmpdir + exit 0