mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Teach parse_util_detect_errors to report invalid builtins, as found in
issue #1252
This commit is contained in:
parent
f2a437bd3b
commit
0325c1ba65
3 changed files with 16 additions and 2 deletions
|
@ -3760,7 +3760,7 @@ int builtin_run(parser_t &parser, const wchar_t * const *argv, const io_chain_t
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug(0, _(L"Unknown builtin '%ls'"), argv[0]);
|
debug(0, UNKNOWN_BUILTIN_ERR_MSG, argv[0]);
|
||||||
}
|
}
|
||||||
return STATUS_BUILTIN_ERROR;
|
return STATUS_BUILTIN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,6 +183,9 @@ void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt);
|
||||||
/** Error message when encountering an illegal command name */
|
/** Error message when encountering an illegal command name */
|
||||||
#define ILLEGAL_CMD_ERR_MSG _( L"Illegal command name '%ls'")
|
#define ILLEGAL_CMD_ERR_MSG _( L"Illegal command name '%ls'")
|
||||||
|
|
||||||
|
/** Error message when encountering an unknown builtin name */
|
||||||
|
#define UNKNOWN_BUILTIN_ERR_MSG _( L"Unknown builtin '%ls'")
|
||||||
|
|
||||||
/** Error message when encountering a failed expansion, e.g. for the variable name in for loops */
|
/** Error message when encountering a failed expansion, e.g. for the variable name in for loops */
|
||||||
#define FAILED_EXPANSION_VARIABLE_NAME_ERR_MSG _( L"Unable to expand variable name '%ls'")
|
#define FAILED_EXPANSION_VARIABLE_NAME_ERR_MSG _( L"Unable to expand variable name '%ls'")
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "wildcard.h"
|
#include "wildcard.h"
|
||||||
#include "parse_tree.h"
|
#include "parse_tree.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
#include "builtin.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Error message for improper use of the exec builtin
|
Error message for improper use of the exec builtin
|
||||||
|
@ -1288,8 +1289,11 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
|
||||||
// In a few places below, we want to know if we are in a pipeline
|
// In a few places below, we want to know if we are in a pipeline
|
||||||
const bool is_in_pipeline = node_tree.statement_is_in_pipeline(node, true /* count first */);
|
const bool is_in_pipeline = node_tree.statement_is_in_pipeline(node, true /* count first */);
|
||||||
|
|
||||||
|
// We need to know the decoration
|
||||||
|
const enum parse_statement_decoration_t decoration = node_tree.decoration_for_plain_statement(node);
|
||||||
|
|
||||||
// Check that we don't try to pipe through exec
|
// Check that we don't try to pipe through exec
|
||||||
if (is_in_pipeline && node_tree.decoration_for_plain_statement(node) == parse_statement_decoration_exec)
|
if (is_in_pipeline && decoration == parse_statement_decoration_exec)
|
||||||
{
|
{
|
||||||
errored = append_syntax_error(&parse_errors, node, EXEC_ERR_MSG, L"exec");
|
errored = append_syntax_error(&parse_errors, node, EXEC_ERR_MSG, L"exec");
|
||||||
}
|
}
|
||||||
|
@ -1380,6 +1384,13 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
|
||||||
errored = append_syntax_error(&parse_errors, node, (command == L"break" ? INVALID_BREAK_ERR_MSG : INVALID_CONTINUE_ERR_MSG));
|
errored = append_syntax_error(&parse_errors, node, (command == L"break" ? INVALID_BREAK_ERR_MSG : INVALID_CONTINUE_ERR_MSG));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that we don't do an invalid builtin (#1252)
|
||||||
|
if (! errored && decoration == parse_statement_decoration_builtin && ! builtin_exists(command))
|
||||||
|
{
|
||||||
|
errored = append_syntax_error(&parse_errors, node, UNKNOWN_BUILTIN_ERR_MSG, command.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue