mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-24 17:41:16 -03:00
add function --shadow-builtin flag
It's currently too easy for someone to bork their shell by doing something like `function test; return 0; end`. That's obviously a silly, contrived, example but the point is that novice users who learn about functions are prone to do something like that without realizing it will bork the shell. Even expert users who know about the `test` builtin might forget that, say, `pwd` is a builtin. This change adds a `--shadow-builtin` flag that must be specified to indicate you know what you're doing. Fixes #3000
This commit is contained in:
@@ -141,7 +141,8 @@ function_info_t::function_info_t(const function_data_t &data, const wchar_t *fil
|
||||
named_arguments(data.named_arguments),
|
||||
inherit_vars(snapshot_vars(data.inherit_vars)),
|
||||
is_autoload(autoload),
|
||||
shadows(data.shadows) {}
|
||||
shadow_builtin(data.shadow_builtin),
|
||||
shadow_scope(data.shadow_scope) {}
|
||||
|
||||
function_info_t::function_info_t(const function_info_t &data, const wchar_t *filename,
|
||||
int def_offset, bool autoload)
|
||||
@@ -152,7 +153,8 @@ function_info_t::function_info_t(const function_info_t &data, const wchar_t *fil
|
||||
named_arguments(data.named_arguments),
|
||||
inherit_vars(data.inherit_vars),
|
||||
is_autoload(autoload),
|
||||
shadows(data.shadows) {}
|
||||
shadow_builtin(data.shadow_builtin),
|
||||
shadow_scope(data.shadow_scope) {}
|
||||
|
||||
void function_add(const function_data_t &data, const parser_t &parser, int definition_line_offset) {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
@@ -255,10 +257,16 @@ std::map<wcstring, env_var_t> function_get_inherit_vars(const wcstring &name) {
|
||||
return func ? func->inherit_vars : std::map<wcstring, env_var_t>();
|
||||
}
|
||||
|
||||
int function_get_shadows(const wcstring &name) {
|
||||
int function_get_shadow_builtin(const wcstring &name) {
|
||||
scoped_lock lock(functions_lock);
|
||||
const function_info_t *func = function_get(name);
|
||||
return func ? func->shadows : false;
|
||||
return func ? func->shadow_builtin : false;
|
||||
}
|
||||
|
||||
int function_get_shadow_scope(const wcstring &name) {
|
||||
scoped_lock lock(functions_lock);
|
||||
const function_info_t *func = function_get(name);
|
||||
return func ? func->shadow_scope : false;
|
||||
}
|
||||
|
||||
bool function_get_desc(const wcstring &name, wcstring *out_desc) {
|
||||
|
||||
Reference in New Issue
Block a user