Parse command substitution in regex correctly (#43395)
@@ -8,6 +8,13 @@ | ||
8 | 8 | x: new bug |
9 | 9 | |
10 | 10 | ---------------------------------------------------------------------- |
11 | +Yash 2.53 (????-??-??) | |
12 | + | |
13 | + * Fixed a bug where command substitutions contained in the regular | |
14 | + expression inside the "[[ word =~ regex ]]" syntax were not | |
15 | + parsed correctly. | |
16 | + | |
17 | +---------------------------------------------------------------------- | |
11 | 18 | Yash 2.52 (2021-10-11) |
12 | 19 | |
13 | 20 | = Unquoted multiple empty fields resulting from a single word |
@@ -2937,8 +2937,8 @@ | ||
2937 | 2937 | |
2938 | 2938 | /* So, before calling this function, the current token must have been parsed |
2939 | 2939 | * as usual by the `next_token' function. We start by examining the current |
2940 | - * status to decide how we continue parsing possible remainder of the token. | |
2941 | - */ | |
2940 | + * status to determine how to continue parsing the token's possible | |
2941 | + * remainder.*/ | |
2942 | 2942 | if (ps->token == NULL) { |
2943 | 2943 | switch (ps->src.contents[ps->index]) { |
2944 | 2944 | case L'(': |
@@ -2954,8 +2954,13 @@ | ||
2954 | 2954 | ps->index = ps->next_index; |
2955 | 2955 | } |
2956 | 2956 | |
2957 | - /* Find the end of the result from the previous `next_token' call. */ | |
2958 | - wordunit_T **lastp = &ps->token; | |
2957 | + /* Keep the word units from being overwritten while parsing inner commands | |
2958 | + * that may be contained in the rest of the token. */ | |
2959 | + wordunit_T *token = ps->token; | |
2960 | + ps->token = NULL; | |
2961 | + | |
2962 | + /* Find the place to append results. */ | |
2963 | + wordunit_T **lastp = &token; | |
2959 | 2964 | while (*lastp != NULL) |
2960 | 2965 | lastp = &(*lastp)->next; |
2961 | 2966 |
@@ -3020,8 +3025,8 @@ | ||
3020 | 3025 | MAKE_WORDUNIT_STRING; |
3021 | 3026 | ps->next_index = ps->index; |
3022 | 3027 | ps->index = grandstartindex; |
3023 | - if (ps->token != NULL) | |
3024 | - ps->tokentype = TT_WORD; | |
3028 | + wordfree(ps->token), ps->token = token; | |
3029 | + ps->tokentype = TT_WORD; | |
3025 | 3030 | return parse_double_bracket_operand(ps); |
3026 | 3031 | } |
3027 | 3032 |