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.
This commit is contained in:
ridiculousfish 2021-06-22 12:37:45 -07:00
parent 4a3df618f2
commit 3b4c71c546
2 changed files with 5 additions and 3 deletions

View File

@ -184,6 +184,7 @@ std::shared_ptr<const function_properties_t> 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.

View File

@ -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.
///