mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.4841: empty string considered an error for expand()
Problem: Empty string considered an error for expand() when 'verbose' is set. (Christian Brabandt) Solution: Do not give an error for an empty result. (closes #10307)
This commit is contained in:
@@ -4105,7 +4105,7 @@ f_expand(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
if (p_verbose == 0)
|
if (p_verbose == 0)
|
||||||
++emsg_off;
|
++emsg_off;
|
||||||
result = eval_vars(s, s, &len, NULL, &errormsg, NULL);
|
result = eval_vars(s, s, &len, NULL, &errormsg, NULL, FALSE);
|
||||||
if (p_verbose == 0)
|
if (p_verbose == 0)
|
||||||
--emsg_off;
|
--emsg_off;
|
||||||
else if (errormsg != NULL)
|
else if (errormsg != NULL)
|
||||||
|
@@ -4924,7 +4924,7 @@ expand_filename(
|
|||||||
* Try to find a match at this position.
|
* Try to find a match at this position.
|
||||||
*/
|
*/
|
||||||
repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum),
|
repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum),
|
||||||
errormsgp, &escaped);
|
errormsgp, &escaped, TRUE);
|
||||||
if (*errormsgp != NULL) // error detected
|
if (*errormsgp != NULL) // error detected
|
||||||
return FAIL;
|
return FAIL;
|
||||||
if (repl == NULL) // no match found
|
if (repl == NULL) // no match found
|
||||||
@@ -9045,8 +9045,9 @@ eval_vars(
|
|||||||
int *usedlen, // characters after src that are used
|
int *usedlen, // characters after src that are used
|
||||||
linenr_T *lnump, // line number for :e command, or NULL
|
linenr_T *lnump, // line number for :e command, or NULL
|
||||||
char **errormsg, // pointer to error message
|
char **errormsg, // pointer to error message
|
||||||
int *escaped) // return value has escaped white space (can
|
int *escaped, // return value has escaped white space (can
|
||||||
// be NULL)
|
// be NULL)
|
||||||
|
int empty_is_error) // empty result is considered an error
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char_u *s;
|
char_u *s;
|
||||||
@@ -9348,7 +9349,7 @@ eval_vars(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultlen == 0 || valid != VALID_HEAD + VALID_PATH)
|
if (empty_is_error && (resultlen == 0 || valid != VALID_HEAD + VALID_PATH))
|
||||||
{
|
{
|
||||||
if (valid != VALID_HEAD + VALID_PATH)
|
if (valid != VALID_HEAD + VALID_PATH)
|
||||||
*errormsg = _(e_empty_file_name_for_percent_or_hash_only_works_with_ph);
|
*errormsg = _(e_empty_file_name_for_percent_or_hash_only_works_with_ph);
|
||||||
@@ -9389,7 +9390,7 @@ expand_sfile(char_u *arg)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// replace "<sfile>" with the sourced file name, and do ":" stuff
|
// replace "<sfile>" with the sourced file name, and do ":" stuff
|
||||||
repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL);
|
repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL, TRUE);
|
||||||
if (errormsg != NULL)
|
if (errormsg != NULL)
|
||||||
{
|
{
|
||||||
if (*errormsg)
|
if (*errormsg)
|
||||||
|
@@ -3097,7 +3097,7 @@ expand_wildcards_eval(
|
|||||||
{
|
{
|
||||||
++emsg_off;
|
++emsg_off;
|
||||||
eval_pat = eval_vars(exp_pat, exp_pat, &usedlen,
|
eval_pat = eval_vars(exp_pat, exp_pat, &usedlen,
|
||||||
NULL, &ignored_msg, NULL);
|
NULL, &ignored_msg, NULL, TRUE);
|
||||||
--emsg_off;
|
--emsg_off;
|
||||||
if (eval_pat != NULL)
|
if (eval_pat != NULL)
|
||||||
exp_pat = concat_str(eval_pat, exp_pat + usedlen);
|
exp_pat = concat_str(eval_pat, exp_pat + usedlen);
|
||||||
|
@@ -63,7 +63,7 @@ void ex_normal(exarg_T *eap);
|
|||||||
void exec_normal_cmd(char_u *cmd, int remap, int silent);
|
void exec_normal_cmd(char_u *cmd, int remap, int silent);
|
||||||
void exec_normal(int was_typed, int use_vpeekc, int may_use_terminal_loop);
|
void exec_normal(int was_typed, int use_vpeekc, int may_use_terminal_loop);
|
||||||
int find_cmdline_var(char_u *src, int *usedlen);
|
int find_cmdline_var(char_u *src, int *usedlen);
|
||||||
char_u *eval_vars(char_u *src, char_u *srcstart, int *usedlen, linenr_T *lnump, char **errormsg, int *escaped);
|
char_u *eval_vars(char_u *src, char_u *srcstart, int *usedlen, linenr_T *lnump, char **errormsg, int *escaped, int empty_is_error);
|
||||||
char_u *expand_sfile(char_u *arg);
|
char_u *expand_sfile(char_u *arg);
|
||||||
void dialog_msg(char_u *buff, char *format, char_u *fname);
|
void dialog_msg(char_u *buff, char *format, char_u *fname);
|
||||||
void set_no_hlsearch(int flag);
|
void set_no_hlsearch(int flag);
|
||||||
|
@@ -82,10 +82,14 @@ endfunc
|
|||||||
|
|
||||||
func Test_expand()
|
func Test_expand()
|
||||||
new
|
new
|
||||||
call assert_equal("", expand('%:S'))
|
call assert_equal("''", expand('%:S'))
|
||||||
call assert_equal('3', '<slnum>'->expand())
|
call assert_equal('3', '<slnum>'->expand())
|
||||||
call assert_equal(['4'], expand('<slnum>', v:false, v:true))
|
call assert_equal(['4'], expand('<slnum>', v:false, v:true))
|
||||||
" Don't add any line above this, otherwise <slnum> will change.
|
" Don't add any line above this, otherwise <slnum> will change.
|
||||||
|
call assert_equal("", expand('%'))
|
||||||
|
set verbose=1
|
||||||
|
call assert_equal("", expand('%'))
|
||||||
|
set verbose=0
|
||||||
quit
|
quit
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -746,6 +746,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4841,
|
||||||
/**/
|
/**/
|
||||||
4840,
|
4840,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user