diff --git a/CHANGELOG.md b/CHANGELOG.md index 027ace869..ad522690a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/src/parser_keywords.cpp b/src/parser_keywords.cpp index 015aac12b..12676c266 100644 --- a/src/parser_keywords.cpp +++ b/src/parser_keywords.cpp @@ -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); diff --git a/tests/function.err b/tests/function.err index 06cdb1698..2d69cbb05 100644 --- a/tests/function.err +++ b/tests/function.err @@ -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 +^ diff --git a/tests/function.in b/tests/function.in index c0b324f97..5f64ed777 100644 --- a/tests/function.in +++ b/tests/function.in @@ -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 diff --git a/tests/function.out b/tests/function.out index 064f58164..95a79ed2f 100644 --- a/tests/function.out +++ b/tests/function.out @@ -70,3 +70,6 @@ Function name4 not found as expected < function name3 --argument arg1 arg2 --- > function name3a --argument arg1 arg2 + +#################### +# Checking reserved names