diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-06-06 12:33:49 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-06 12:33:49 +0200 |
commit | 7a2217bedd223df4c8bbebe731bf0b5fe8532533 (patch) | |
tree | 2e0bd662dc0ebdcd248084dc15f9a1ccdb06223f | |
parent | f5bfa8faa7bbe025c10148d37e8b47217a430a3b (diff) | |
download | vim-git-7a2217bedd223df4c8bbebe731bf0b5fe8532533.tar.gz |
patch 8.2.2948: substitute() accepts a number but not a float expressionv8.2.2948
Problem: Substitute() accepts a number but not a float expression.
Solution: Also accept a float. (closes #8331)
-rw-r--r-- | src/testdir/test_substitute.vim | 8 | ||||
-rw-r--r-- | src/typval.c | 9 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim index 4c99f8187..0c367485b 100644 --- a/src/testdir/test_substitute.vim +++ b/src/testdir/test_substitute.vim @@ -1,6 +1,7 @@ " Tests for multi-line regexps with ":s". source shared.vim +source check.vim func Test_multiline_subst() enew! @@ -453,6 +454,13 @@ func Test_substitute_partial() call assert_fails("call substitute('123', '2', Replacer, 'g')", 'E118:') endfunc +func Test_substitute_float() + CheckFeature float + + call assert_equal('number 1.23', substitute('number ', '$', { -> 1.23 }, '')) + vim9 assert_equal('number 1.23', substitute('number ', '$', () => 1.23, '')) +endfunc + " Tests for *sub-replace-special* and *sub-replace-expression* on :substitute. " Execute a list of :substitute command tests diff --git a/src/typval.c b/src/typval.c index f08d1aa42..a17dbef7e 100644 --- a/src/typval.c +++ b/src/typval.c @@ -462,8 +462,13 @@ tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict) break; case VAR_FLOAT: #ifdef FEAT_FLOAT - emsg(_(e_float_as_string)); - break; + if (strict) + { + emsg(_(e_float_as_string)); + break; + } + vim_snprintf((char *)buf, NUMBUFLEN, "%g", varp->vval.v_float); + return buf; #endif case VAR_STRING: if (varp->vval.v_string != NULL) diff --git a/src/version.c b/src/version.c index 7bc2afcec..b9df68801 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2948, +/**/ 2947, /**/ 2946, |