mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Properly parse spaces and escaped/quoted spaces in expansion braces
This commit is contained in:
parent
00f95a978e
commit
1629d339de
3 changed files with 14 additions and 14 deletions
|
@ -1288,10 +1288,10 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
const bool unescape_special = static_cast<bool>(flags & UNESCAPE_SPECIAL);
|
const bool unescape_special = static_cast<bool>(flags & UNESCAPE_SPECIAL);
|
||||||
const bool allow_incomplete = static_cast<bool>(flags & UNESCAPE_INCOMPLETE);
|
const bool allow_incomplete = static_cast<bool>(flags & UNESCAPE_INCOMPLETE);
|
||||||
|
|
||||||
int bracket_count = 0;
|
int brace_count = 0;
|
||||||
|
|
||||||
bool errored = false;
|
bool errored = false;
|
||||||
enum { mode_unquoted, mode_single_quotes, mode_double_quotes } mode = mode_unquoted;
|
enum { mode_unquoted, mode_single_quotes, mode_double_quotes, mode_braces } mode = mode_unquoted;
|
||||||
|
|
||||||
for (size_t input_position = 0; input_position < input_len && !errored; input_position++) {
|
for (size_t input_position = 0; input_position < input_len && !errored; input_position++) {
|
||||||
const wchar_t c = input[input_position];
|
const wchar_t c = input[input_position];
|
||||||
|
@ -1352,24 +1352,31 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
}
|
}
|
||||||
case L'{': {
|
case L'{': {
|
||||||
if (unescape_special) {
|
if (unescape_special) {
|
||||||
bracket_count++;
|
brace_count++;
|
||||||
to_append_or_none = BRACE_BEGIN;
|
to_append_or_none = BRACE_BEGIN;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L'}': {
|
case L'}': {
|
||||||
if (unescape_special) {
|
if (unescape_special) {
|
||||||
bracket_count--;
|
brace_count--;
|
||||||
to_append_or_none = BRACE_END;
|
to_append_or_none = BRACE_END;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L',': {
|
case L',': {
|
||||||
if (unescape_special && bracket_count > 0) {
|
if (unescape_special && brace_count > 0) {
|
||||||
to_append_or_none = BRACE_SEP;
|
to_append_or_none = BRACE_SEP;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case L' ': {
|
||||||
|
//spaces, unless quoted or escaped, are ignored within braces
|
||||||
|
// if (unescape_special && brace_count > 0) {
|
||||||
|
// input_position++; //skip the space
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
}
|
||||||
case L'\'': {
|
case L'\'': {
|
||||||
mode = mode_single_quotes;
|
mode = mode_single_quotes;
|
||||||
to_append_or_none = unescape_special ? wint_t(INTERNAL_SEPARATOR) : NOT_A_WCHAR;
|
to_append_or_none = unescape_special ? wint_t(INTERNAL_SEPARATOR) : NOT_A_WCHAR;
|
||||||
|
|
|
@ -942,8 +942,8 @@ static expand_error_t expand_braces(const wcstring &instr, expand_flags_t flags,
|
||||||
whole_item.append(in, length_preceding_braces);
|
whole_item.append(in, length_preceding_braces);
|
||||||
whole_item.append(item_begin, item_len);
|
whole_item.append(item_begin, item_len);
|
||||||
whole_item.append(brace_end + 1);
|
whole_item.append(brace_end + 1);
|
||||||
auto whole_item2 = trim(whole_item);
|
whole_item = trim(whole_item);
|
||||||
debug(0, L"Found brace item: %ls\n", whole_item2.c_str());
|
// debug(0, L"Found brace item: '%ls'\n", whole_item.c_str());
|
||||||
expand_braces(whole_item, flags, out, errors);
|
expand_braces(whole_item, flags, out, errors);
|
||||||
|
|
||||||
item_begin = pos + 1;
|
item_begin = pos + 1;
|
||||||
|
|
|
@ -47,13 +47,6 @@ wcstring truncate(const wcstring &input, int max_len, ellipsis_type etype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wcstring trim(const wcstring &input) {
|
wcstring trim(const wcstring &input) {
|
||||||
debug(0, "trimming '%ls'", input.c_str());
|
|
||||||
|
|
||||||
// auto begin = input.cbegin();
|
|
||||||
// for (begin; *begin == L' '; ++begin);
|
|
||||||
// auto end = input.cbegin() + input.size();
|
|
||||||
// for (end; end > begin && *end == L' '; ++end);
|
|
||||||
|
|
||||||
auto begin_offset = input.find_first_not_of(whitespace);
|
auto begin_offset = input.find_first_not_of(whitespace);
|
||||||
if (begin_offset == wcstring::npos) {
|
if (begin_offset == wcstring::npos) {
|
||||||
return wcstring{};
|
return wcstring{};
|
||||||
|
|
Loading…
Reference in a new issue