mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
fix incorrectly aligned carat in command expansion errors and more
- fix the carat position expanding e.g. `command $,` - improve the error reporting for not-allowed command subtitutions by figuring out where the expansion failed instead of using SOURCE_LOCATION_UNKNOWN - allow nullptr for parse_util_licate_brackets_range() out_string argument if we don't need it to do any work. Fixes #5812
This commit is contained in:
parent
4539a9db15
commit
75db3b4ff4
2 changed files with 15 additions and 9 deletions
|
@ -879,13 +879,16 @@ static expand_error_t expand_stage_cmdsubst(wcstring input, std::vector<completi
|
|||
parse_error_list_t *errors) {
|
||||
UNUSED(vars);
|
||||
if (EXPAND_SKIP_CMDSUBST & flags) {
|
||||
wchar_t *begin, *end;
|
||||
if (parse_util_locate_cmdsubst(input.c_str(), &begin, &end, true) == 0) {
|
||||
append_completion(out, std::move(input));
|
||||
} else {
|
||||
append_cmdsub_error(errors, SOURCE_LOCATION_UNKNOWN,
|
||||
L"Command substitutions not allowed");
|
||||
return EXPAND_ERROR;
|
||||
size_t cur = 0, start = 0, end;
|
||||
switch (parse_util_locate_cmdsubst_range(input, &cur, nullptr, &start, &end, true)) {
|
||||
case 0:
|
||||
append_completion(out, std::move(input));
|
||||
break;
|
||||
case 1: /* fallthroughs intentional */
|
||||
append_cmdsub_error(errors, start, L"Command substitutions not allowed");
|
||||
case -1:
|
||||
default:
|
||||
return EXPAND_ERROR;
|
||||
}
|
||||
} else {
|
||||
bool cmdsubst_ok = expand_cmdsubst(std::move(input), out, errors);
|
||||
|
|
|
@ -185,7 +185,7 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c
|
|||
size_t *out_end, bool accept_incomplete,
|
||||
wchar_t open_type, wchar_t close_type) {
|
||||
// Clear the return values.
|
||||
out_contents->clear();
|
||||
if (out_contents != nullptr) out_contents->clear();
|
||||
*out_start = 0;
|
||||
*out_end = str.size();
|
||||
|
||||
|
@ -213,7 +213,9 @@ static int parse_util_locate_brackets_range(const wcstring &str, size_t *inout_c
|
|||
|
||||
// Assign the substring to the out_contents.
|
||||
const wchar_t *interior_begin = bracket_range_begin + 1;
|
||||
out_contents->assign(interior_begin, bracket_range_end - interior_begin);
|
||||
if (out_contents != nullptr) {
|
||||
out_contents->assign(interior_begin, bracket_range_end - interior_begin);
|
||||
}
|
||||
|
||||
// Return the start and end.
|
||||
*out_start = bracket_range_begin - buff;
|
||||
|
@ -1134,6 +1136,7 @@ static bool detect_errors_in_plain_statement(const wcstring &buff_src,
|
|||
if (expand_to_command_and_args(*unexp_command, null_environment_t{}, &command, nullptr,
|
||||
parse_errors) == EXPAND_ERROR) {
|
||||
errored = true;
|
||||
parse_error_offset_source_start(parse_errors, source_start);
|
||||
}
|
||||
|
||||
// Check that pipes are sound.
|
||||
|
|
Loading…
Reference in a new issue