Reserve some builtin names

`argparse`, `read`, `set`, `status`, `test` and `[` now can't be used
as function names anymore.

This is because (except for `test` and `[`) there is no way to wrap these properly, so any
function called that will be broken anyway.

For `test` (and `[`), there is nothing that can be added and there
have been confused users who created a function that then broke
everything.

Fixes #3000.
This commit is contained in:
Fabian Homborg 2018-02-25 19:25:29 +01:00
parent 5648322993
commit 69f68d31df
5 changed files with 14 additions and 1 deletions

View File

@ -40,6 +40,7 @@ This section is for changes merged to the `major` branch that are not also merge
- The pager will now show the full command instead of just its last line if the number of completions is large (#4702).
- Tildes in file names are now properly escaped in completions (#2274)
- A pipe at the end of a line now allows the job to continue on the next line (#1285)
- The names `argparse`, `read`, `set`, `status`, `test` and `[` are now reserved and not allowed as function names. This prevents users unintentionally breaking stuff (#3000).
## Other significant changes
- Command substitution output is now limited to 10 MB by default (#3822).

View File

@ -22,7 +22,7 @@ static const wcstring_list_t block_keywords({L"for", L"while", L"if", L"function
bool parser_keywords_is_block(const wcstring &word) { return contains(block_keywords, word); }
static const wcstring_list_t reserved_keywords({L"end", L"case", L"else", L"return", L"continue",
L"break"});
L"break", L"argparse", L"read", L"set", L"status", L"test", L"["});
bool parser_keywords_is_reserved(const wcstring &word) {
return parser_keywords_is_block(word) || parser_keywords_is_subcommand(word) ||
contains(reserved_keywords, word);

View File

@ -22,3 +22,10 @@ function name5 abc --argument-names def ; end
####################
# Checking that the copied functions are identical other than the name
####################
# Checking reserved names
fish: function: The name 'test' is reserved,
and can not be used as a function name
function test; echo banana; end
^

View File

@ -46,4 +46,6 @@ logmsg Checking that the copied functions are identical other than the name
diff (functions name1 | psub) (functions name1a | psub)
diff (functions name3 | psub) (functions name3a | psub)
logmsg Checking reserved names
function test; echo banana; end
exit 0

View File

@ -70,3 +70,6 @@ Function name4 not found as expected
< function name3 --argument arg1 arg2
---
> function name3a --argument arg1 arg2
####################
# Checking reserved names