diff options
author | Bram Moolenaar <bram@zimbu.org> | 2010-03-23 16:27:22 +0100 |
---|---|---|
committer | Bram Moolenaar <bram@zimbu.org> | 2010-03-23 16:27:22 +0100 |
commit | 2875472bdc1351716786db2cc43201a56d2daee9 (patch) | |
tree | 4eca8331ba5898a0dbd0611e15176b11341e77c7 | |
parent | c6a6b87682a44aaa7863d21466dcb78483080c5a (diff) | |
download | vim-2875472bdc1351716786db2cc43201a56d2daee9.tar.gz |
Problem: When using an expression in ":s" backslashes in the result are
dropped. (Sergey Goldgaber, Christian Brabandt)
Solution: Double backslashes.
-rw-r--r-- | src/regexp.c | 15 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/regexp.c b/src/regexp.c index 037222e0..216bf3a1 100644 --- a/src/regexp.c +++ b/src/regexp.c @@ -6963,6 +6963,8 @@ vim_regsub_both(source, dest, copy, magic, backslash) eval_result = eval_to_string(source + 2, NULL, TRUE); if (eval_result != NULL) { + int had_backslash = FALSE; + for (s = eval_result; *s != NUL; mb_ptr_adv(s)) { /* Change NL to CR, so that it becomes a line break. @@ -6970,7 +6972,20 @@ vim_regsub_both(source, dest, copy, magic, backslash) if (*s == NL) *s = CAR; else if (*s == '\\' && s[1] != NUL) + { ++s; + had_backslash = TRUE; + } + } + if (had_backslash && backslash) + { + /* Backslashes will be consumed, need to double them. */ + s = vim_strsave_escaped(eval_result, (char_u *)"\\"); + if (s != NULL) + { + vim_free(eval_result); + eval_result = s; + } } dst += STRLEN(eval_result); diff --git a/src/version.c b/src/version.c index 59092b38..c10a627e 100644 --- a/src/version.c +++ b/src/version.c @@ -682,6 +682,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 407, +/**/ 406, /**/ 405, |