# HG changeset patch # User Bram Moolenaar # Date 1651169703 -7200 # Node ID 5cf6dee0f3053a056340b8face7a6003f40a2645 # Parent ba9fa3a26a17efacea39cccb0c0d34bbf2776ec2 patch 8.2.4842: expand("%:p") is not empty when there is no buffer name Commit: https://github.com/vim/vim/commit/211a5bb2353c66684f38527184a258921f95c9d9 Author: Bram Moolenaar Date: Thu Apr 28 19:09:03 2022 +0100 patch 8.2.4842: expand("%:p") is not empty when there is no buffer name Problem: expand("%:p") is not empty when there is no buffer name. Solution: When ignoring errors still return NULL. (closes https://github.com/vim/vim/issues/10311) diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -9349,12 +9349,15 @@ eval_vars( } } - if (empty_is_error && (resultlen == 0 || valid != VALID_HEAD + VALID_PATH)) - { - if (valid != VALID_HEAD + VALID_PATH) - *errormsg = _(e_empty_file_name_for_percent_or_hash_only_works_with_ph); - else - *errormsg = _(e_evaluates_to_an_empty_string); + if (resultlen == 0 || valid != VALID_HEAD + VALID_PATH) + { + if (empty_is_error) + { + if (valid != VALID_HEAD + VALID_PATH) + *errormsg = _(e_empty_file_name_for_percent_or_hash_only_works_with_ph); + else + *errormsg = _(e_evaluates_to_an_empty_string); + } result = NULL; } else diff --git a/src/testdir/test_expand_func.vim b/src/testdir/test_expand_func.vim --- a/src/testdir/test_expand_func.vim +++ b/src/testdir/test_expand_func.vim @@ -82,7 +82,7 @@ endfunc func Test_expand() new - call assert_equal("''", expand('%:S')) + call assert_equal("", expand('%:S')) call assert_equal('3', ''->expand()) call assert_equal(['4'], expand('', v:false, v:true)) " Don't add any line above this, otherwise will change. @@ -90,6 +90,7 @@ func Test_expand() set verbose=1 call assert_equal("", expand('%')) set verbose=0 + call assert_equal("", expand('%:p')) quit endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4842, +/**/ 4841, /**/ 4840,