From 3b4c71c54659f24ec6cf8e64ca7de6f71a3cd08b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 22 Jun 2021 12:37:45 -0700 Subject: [PATCH] Catch invalid function names in highlighting and autosuggestion Prior to this change, if you were to type `./fish_indent` it woul dbe colored as valid, because the path `$fish_functions_path/./fish_indent.fish` is a real file. However of course this is not actually executed as a function. Teach function_exists to return false for function names which are invalid. --- src/function.cpp | 6 ++++-- src/function.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/function.cpp b/src/function.cpp index f65d3414d..59fa9b8cb 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -184,6 +184,7 @@ std::shared_ptr function_get_properties(const wcstr int function_exists(const wcstring &cmd, parser_t &parser) { ASSERT_IS_MAIN_THREAD(); + if (!valid_func_name(cmd)) return false; if (parser_keywords_is_reserved(cmd)) return 0; try_autoload(cmd, parser); auto funcset = function_set.acquire(); @@ -197,8 +198,9 @@ void function_load(const wcstring &cmd, parser_t &parser) { } } -int function_exists_no_autoload(const wcstring &cmd) { - if (parser_keywords_is_reserved(cmd)) return 0; +bool function_exists_no_autoload(const wcstring &cmd) { + if (!valid_func_name(cmd)) return false; + if (parser_keywords_is_reserved(cmd)) return false; auto funcset = function_set.acquire(); // Check if we either have the function, or it could be autoloaded. diff --git a/src/function.h b/src/function.h index e7e477cbd..8af4d8649 100644 --- a/src/function.h +++ b/src/function.h @@ -72,7 +72,7 @@ int function_exists(const wcstring &cmd, parser_t &parser); void function_load(const wcstring &cmd, parser_t &parser); /// Returns true if the function with the name name exists, without triggering autoload. -int function_exists_no_autoload(const wcstring &cmd); +bool function_exists_no_autoload(const wcstring &cmd); /// Returns all function names. ///