Mercurial > vim
diff src/evalfunc.c @ 23909:5db7d275543c v8.2.2497
patch 8.2.2497: no error when using more than one character for a register
Commit: https://github.com/vim/vim/commit/418a29f0ffcaa0a3d778724ab6d1111db525d3cc
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 10 22:23:41 2021 +0100
patch 8.2.2497: no error when using more than one character for a register
Problem: No error when using more than one character for a register name.
Solution: In Vim9 script check for a single character string. (closes https://github.com/vim/vim/issues/7814)
Fix that VAR_BOOL and VAR_SPECIAL are not considered equal.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 10 Feb 2021 22:30:06 +0100 |
parents | a9ed31ab85c3 |
children | 44be09b25619 |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4285,7 +4285,13 @@ f_getreg(typval_T *argvars, typval_T *re if (argvars[0].v_type != VAR_UNKNOWN) { strregname = tv_get_string_chk(&argvars[0]); - error = strregname == NULL; + if (strregname == NULL) + error = TRUE; + else if (in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + error = TRUE; + } if (argvars[1].v_type != VAR_UNKNOWN) { arg2 = (int)tv_get_bool_chk(&argvars[1], &error); @@ -4335,6 +4341,11 @@ f_getregtype(typval_T *argvars, typval_T if (argvars[0].v_type != VAR_UNKNOWN) { strregname = tv_get_string_chk(&argvars[0]); + if (strregname != NULL && in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + strregname = NULL; + } if (strregname == NULL) // type error; errmsg already given { rettv->v_type = VAR_STRING; @@ -7368,6 +7379,11 @@ f_getreginfo(typval_T *argvars, typval_T strregname = tv_get_string_chk(&argvars[0]); if (strregname == NULL) return; + if (in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + return; + } } else strregname = get_vim_var_str(VV_REG); @@ -7410,7 +7426,7 @@ f_getreginfo(typval_T *argvars, typval_T { item->di_tv.v_type = VAR_SPECIAL; item->di_tv.vval.v_number = regname == buf[0] - ? VVAL_TRUE : VVAL_FALSE; + ? VVAL_TRUE : VVAL_FALSE; (void)dict_add(dict, item); } } @@ -8472,6 +8488,11 @@ f_setreg(typval_T *argvars, typval_T *re if (strregname == NULL) return; // type error; errmsg already given + if (in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + return; + } regname = *strregname; if (regname == 0 || regname == '@') regname = '"';