mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
vim-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 vim/vim#10307)
a96edb736d
This commit is contained in:
@@ -1982,7 +1982,7 @@ static void f_expand(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
}
|
}
|
||||||
size_t len;
|
size_t len;
|
||||||
char *errormsg = NULL;
|
char *errormsg = NULL;
|
||||||
char_u *result = eval_vars((char_u *)s, (char_u *)s, &len, NULL, &errormsg, NULL);
|
char_u *result = eval_vars((char_u *)s, (char_u *)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) {
|
||||||
|
@@ -3705,7 +3705,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp)
|
|||||||
size_t srclen;
|
size_t srclen;
|
||||||
int escaped;
|
int escaped;
|
||||||
char *repl = (char *)eval_vars((char_u *)p, (char_u *)eap->arg, &srclen, &(eap->do_ecmd_lnum),
|
char *repl = (char *)eval_vars((char_u *)p, (char_u *)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;
|
||||||
}
|
}
|
||||||
@@ -6640,12 +6640,13 @@ ssize_t find_cmdline_var(const char_u *src, size_t *usedlen)
|
|||||||
/// @param lnump line number for :e command, or NULL
|
/// @param lnump line number for :e command, or NULL
|
||||||
/// @param errormsg pointer to error message
|
/// @param errormsg pointer to error message
|
||||||
/// @param escaped return value has escaped white space (can be NULL)
|
/// @param escaped return value has escaped white space (can be NULL)
|
||||||
|
/// @param empty_is_error empty result is considered an error
|
||||||
///
|
///
|
||||||
/// @return an allocated string if a valid match was found.
|
/// @return an allocated string if a valid match was found.
|
||||||
/// Returns NULL if no match was found. "usedlen" then still contains the
|
/// Returns NULL if no match was found. "usedlen" then still contains the
|
||||||
/// number of characters to skip.
|
/// number of characters to skip.
|
||||||
char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnump, char **errormsg,
|
char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnump, char **errormsg,
|
||||||
int *escaped)
|
int *escaped, bool empty_is_error)
|
||||||
{
|
{
|
||||||
char *result;
|
char *result;
|
||||||
char *resultbuf = NULL;
|
char *resultbuf = NULL;
|
||||||
@@ -6890,7 +6891,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
// xgettext:no-c-format
|
// xgettext:no-c-format
|
||||||
*errormsg = _("E499: Empty file name for '%' or '#', only works with \":p:h\"");
|
*errormsg = _("E499: Empty file name for '%' or '#', only works with \":p:h\"");
|
||||||
@@ -6919,7 +6920,8 @@ char *expand_sfile(char *arg)
|
|||||||
// replace "<sfile>" with the sourced file name, and do ":" stuff
|
// replace "<sfile>" with the sourced file name, and do ":" stuff
|
||||||
size_t srclen;
|
size_t srclen;
|
||||||
char *errormsg;
|
char *errormsg;
|
||||||
char *repl = (char *)eval_vars((char_u *)p, (char_u *)result, &srclen, NULL, &errormsg, NULL);
|
char *repl = (char *)eval_vars((char_u *)p, (char_u *)result, &srclen, NULL, &errormsg, NULL,
|
||||||
|
true);
|
||||||
if (errormsg != NULL) {
|
if (errormsg != NULL) {
|
||||||
if (*errormsg) {
|
if (*errormsg) {
|
||||||
emsg(errormsg);
|
emsg(errormsg);
|
||||||
|
@@ -2135,7 +2135,8 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags)
|
|||||||
|
|
||||||
if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<') {
|
if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<') {
|
||||||
emsg_off++;
|
emsg_off++;
|
||||||
eval_pat = eval_vars((char_u *)exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg, NULL);
|
eval_pat = eval_vars((char_u *)exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg, NULL,
|
||||||
|
true);
|
||||||
emsg_off--;
|
emsg_off--;
|
||||||
if (eval_pat != NULL) {
|
if (eval_pat != NULL) {
|
||||||
exp_pat = (char *)concat_str(eval_pat, (char_u *)exp_pat + usedlen);
|
exp_pat = (char *)concat_str(eval_pat, (char_u *)exp_pat + usedlen);
|
||||||
|
@@ -107,10 +107,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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user