]> granicus.if.org Git - vim/commitdiff
patch 8.2.4842: expand("%:p") is not empty when there is no buffer name v8.2.4842
authorBram Moolenaar <Bram@vim.org>
Thu, 28 Apr 2022 18:09:03 +0000 (19:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 28 Apr 2022 18:09:03 +0000 (19:09 +0100)
Problem:    expand("%:p") is not empty when there is no buffer name.
Solution:   When ignoring errors still return NULL. (closes #10311)

src/ex_docmd.c
src/testdir/test_expand_func.vim
src/version.c

index 226435003de7075e7a162eb93c35fe14a27d9147..f78e4edf2523c439cc5b8f5e080d0d1237ae20d9 100644 (file)
@@ -9349,12 +9349,15 @@ eval_vars(
        }
     }
 
-    if (empty_is_error && (resultlen == 0 || valid != VALID_HEAD + VALID_PATH))
+    if (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 (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
index 59156afe321df6eee6ced962c95691186ed858fc..d9327bf3e53f5a513285a9e03a2f9e8e44c97a96 100644 (file)
@@ -82,7 +82,7 @@ endfunc
 
 func Test_expand()
   new
-  call assert_equal("''", expand('%:S'))
+  call assert_equal("", expand('%:S'))
   call assert_equal('3', '<slnum>'->expand())
   call assert_equal(['4'], expand('<slnum>', v:false, v:true))
   " Don't add any line above this, otherwise <slnum> 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
 
index 31306fb1a4badc278c79ec579534a1eedb5d3a05..0d95a7cac4c1f5e6acd2faedea99db521bec5730 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4842,
 /**/
     4841,
 /**/