Properly parse spaces and escaped/quoted spaces in expansion braces

This commit is contained in:
Mahmoud Al-Qudsi
2018-03-11 19:51:54 -05:00
parent 00f95a978e
commit 1629d339de
3 changed files with 14 additions and 14 deletions

View File

@@ -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 allow_incomplete = static_cast<bool>(flags & UNESCAPE_INCOMPLETE);
int bracket_count = 0;
int brace_count = 0;
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++) {
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'{': {
if (unescape_special) {
bracket_count++;
brace_count++;
to_append_or_none = BRACE_BEGIN;
}
break;
}
case L'}': {
if (unescape_special) {
bracket_count--;
brace_count--;
to_append_or_none = BRACE_END;
}
break;
}
case L',': {
if (unescape_special && bracket_count > 0) {
if (unescape_special && brace_count > 0) {
to_append_or_none = BRACE_SEP;
}
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'\'': {
mode = mode_single_quotes;
to_append_or_none = unescape_special ? wint_t(INTERNAL_SEPARATOR) : NOT_A_WCHAR;