mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-22 18:21:13 -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:
@@ -44,3 +44,16 @@ for i in (seq 4)
|
||||
echo "Function name$i not found, but should have been"
|
||||
end
|
||||
end
|
||||
|
||||
# Test that we can't define a function that shadows a builtin by accident.
|
||||
function pwd; end
|
||||
or echo 'yes, it failed as expected' >&2
|
||||
|
||||
# Test that we can define a function that shadows a builtin if we use the
|
||||
# right flag.
|
||||
function pwd --shadow-builtin; end
|
||||
and echo '"function pwd --shadow-builtin" worked'
|
||||
|
||||
# Using --shadow-builtin for a non-builtin function name also fails.
|
||||
function not_builtin --shadow-builtin; end
|
||||
or echo 'yes, it failed as expected' >&2
|
||||
|
||||
Reference in New Issue
Block a user