Mercurial > vim
comparison src/evalvars.c @ 28821:006d525419fa v8.2.4934
patch 8.2.4934: string interpolation fails when not evaluating
Commit: https://github.com/vim/vim/commit/70c41241c2701f26a99085e433925a206ca265a3
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 10 18:11:43 2022 +0100
patch 8.2.4934: string interpolation fails when not evaluating
Problem: String interpolation fails when not evaluating.
Solution: Skip the expression when not evaluating. (closes https://github.com/vim/vim/issues/10398)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 10 May 2022 19:15:03 +0200 |
parents | 3626ca6a20ea |
children | 84a6794a9320 |
comparison
equal
deleted
inserted
replaced
28820:80efed726323 | 28821:006d525419fa |
---|---|
603 } | 603 } |
604 | 604 |
605 /* | 605 /* |
606 * Evaluate one Vim expression {expr} in string "p" and append the | 606 * Evaluate one Vim expression {expr} in string "p" and append the |
607 * resulting string to "gap". "p" points to the opening "{". | 607 * resulting string to "gap". "p" points to the opening "{". |
608 * When "evaluate" is FALSE only skip over the expression. | |
608 * Return a pointer to the character after "}", NULL for an error. | 609 * Return a pointer to the character after "}", NULL for an error. |
609 */ | 610 */ |
610 char_u * | 611 char_u * |
611 eval_one_expr_in_str(char_u *p, garray_T *gap) | 612 eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate) |
612 { | 613 { |
613 char_u *block_start = skipwhite(p + 1); // skip the opening { | 614 char_u *block_start = skipwhite(p + 1); // skip the opening { |
614 char_u *block_end = block_start; | 615 char_u *block_end = block_start; |
615 char_u *expr_val; | 616 char_u *expr_val; |
616 | 617 |
625 if (*block_end != '}') | 626 if (*block_end != '}') |
626 { | 627 { |
627 semsg(_(e_missing_close_curly_str), p); | 628 semsg(_(e_missing_close_curly_str), p); |
628 return NULL; | 629 return NULL; |
629 } | 630 } |
630 *block_end = NUL; | 631 if (evaluate) |
631 expr_val = eval_to_string(block_start, TRUE); | 632 { |
632 *block_end = '}'; | 633 *block_end = NUL; |
633 if (expr_val == NULL) | 634 expr_val = eval_to_string(block_start, TRUE); |
634 return NULL; | 635 *block_end = '}'; |
635 ga_concat(gap, expr_val); | 636 if (expr_val == NULL) |
636 vim_free(expr_val); | 637 return NULL; |
638 ga_concat(gap, expr_val); | |
639 vim_free(expr_val); | |
640 } | |
637 | 641 |
638 return block_end + 1; | 642 return block_end + 1; |
639 } | 643 } |
640 | 644 |
641 /* | 645 /* |
689 ++p; | 693 ++p; |
690 continue; | 694 continue; |
691 } | 695 } |
692 | 696 |
693 // Evaluate the expression and append the result. | 697 // Evaluate the expression and append the result. |
694 p = eval_one_expr_in_str(p, &ga); | 698 p = eval_one_expr_in_str(p, &ga, TRUE); |
695 if (p == NULL) | 699 if (p == NULL) |
696 { | 700 { |
697 ga_clear(&ga); | 701 ga_clear(&ga); |
698 return NULL; | 702 return NULL; |
699 } | 703 } |