mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-01 18:31:14 -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:
@@ -636,7 +636,7 @@ void exec_job(parser_t &parser, job_t *j) {
|
||||
wcstring def;
|
||||
bool function_exists = function_get_definition(func_name, &def);
|
||||
|
||||
bool shadows = function_get_shadows(func_name);
|
||||
bool shadow_scope = function_get_shadow_scope(func_name);
|
||||
const std::map<wcstring, env_var_t> inherit_vars =
|
||||
function_get_inherit_vars(func_name);
|
||||
|
||||
@@ -646,7 +646,7 @@ void exec_job(parser_t &parser, job_t *j) {
|
||||
debug(0, _(L"Unknown function '%ls'"), p->argv0());
|
||||
break;
|
||||
}
|
||||
function_block_t *newv = new function_block_t(p, func_name, shadows);
|
||||
function_block_t *newv = new function_block_t(p, func_name, shadow_scope);
|
||||
parser.push_block(newv);
|
||||
|
||||
// Setting variables might trigger an event handler, hence we need to unblock
|
||||
|
||||
Reference in New Issue
Block a user