mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 07:18:17 +00:00
vim-patch:7.4.1768
Problem: Arguments of setqflist() are not checked properly.
Solution: Add better checks, add a test. (Nikolai Pavlov, Hirohito Higashi,
closes vim/vim#661)
d106e5ba7f
This commit is contained in:
@@ -158,7 +158,7 @@ static char *e_listdictarg = N_(
|
|||||||
static char *e_emptykey = N_("E713: Cannot use empty key for Dictionary");
|
static char *e_emptykey = N_("E713: Cannot use empty key for Dictionary");
|
||||||
static char *e_listreq = N_("E714: List required");
|
static char *e_listreq = N_("E714: List required");
|
||||||
static char *e_dictreq = N_("E715: Dictionary required");
|
static char *e_dictreq = N_("E715: Dictionary required");
|
||||||
static char *e_strreq = N_("E114: String required");
|
static char *e_stringreq = N_("E928: String required");
|
||||||
static char *e_toomanyarg = N_("E118: Too many arguments for function: %s");
|
static char *e_toomanyarg = N_("E118: Too many arguments for function: %s");
|
||||||
static char *e_dictkey = N_("E716: Key not present in Dictionary: %s");
|
static char *e_dictkey = N_("E716: Key not present in Dictionary: %s");
|
||||||
static char *e_funcexts = N_(
|
static char *e_funcexts = N_(
|
||||||
@@ -14996,6 +14996,7 @@ static void f_setline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv)
|
static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv)
|
||||||
FUNC_ATTR_NONNULL_ARG(2, 3)
|
FUNC_ATTR_NONNULL_ARG(2, 3)
|
||||||
{
|
{
|
||||||
|
static char *e_invact = N_("E927: Invalid action: '%s'");
|
||||||
char_u *title = NULL;
|
char_u *title = NULL;
|
||||||
int action = ' ';
|
int action = ' ';
|
||||||
rettv->vval.v_number = -1;
|
rettv->vval.v_number = -1;
|
||||||
@@ -15011,13 +15012,17 @@ static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv)
|
|||||||
// Option argument was not given.
|
// Option argument was not given.
|
||||||
goto skip_args;
|
goto skip_args;
|
||||||
} else if (action_arg->v_type != VAR_STRING) {
|
} else if (action_arg->v_type != VAR_STRING) {
|
||||||
EMSG(_(e_strreq));
|
EMSG(_(e_stringreq));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char_u *act = get_tv_string_chk(action_arg);
|
char_u *act = get_tv_string_chk(action_arg);
|
||||||
if (*act == 'a' || *act == 'r') {
|
if ((*act == 'a' || *act == 'r' || *act == ' ') && act[1] == NUL) {
|
||||||
action = *act;
|
action = *act;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
EMSG2(_(e_invact), act);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
typval_T *title_arg = &args[2];
|
typval_T *title_arg = &args[2];
|
||||||
if (title_arg->v_type == VAR_UNKNOWN) {
|
if (title_arg->v_type == VAR_UNKNOWN) {
|
||||||
|
@@ -564,8 +564,8 @@ msgstr "E714: Потрібен список"
|
|||||||
msgid "E715: Dictionary required"
|
msgid "E715: Dictionary required"
|
||||||
msgstr "E715: Потрібен словник"
|
msgstr "E715: Потрібен словник"
|
||||||
|
|
||||||
msgid "E114: String required"
|
msgid "E928: String required"
|
||||||
msgstr "E114: Потрібен String"
|
msgstr "E928: Потрібен String"
|
||||||
|
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "E118: Too many arguments for function: %s"
|
msgid "E118: Too many arguments for function: %s"
|
||||||
|
@@ -483,7 +483,7 @@ endfunction
|
|||||||
function Test_locationlist_curwin_was_closed()
|
function Test_locationlist_curwin_was_closed()
|
||||||
augroup testgroup
|
augroup testgroup
|
||||||
au!
|
au!
|
||||||
autocmd BufReadCmd t call R(expand("<amatch>"))
|
autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
function! R(n)
|
function! R(n)
|
||||||
@@ -492,7 +492,7 @@ function Test_locationlist_curwin_was_closed()
|
|||||||
|
|
||||||
new
|
new
|
||||||
let q = []
|
let q = []
|
||||||
call add(q, {'filename': 't' })
|
call add(q, {'filename': 'test_curwin.txt' })
|
||||||
call setloclist(0, q)
|
call setloclist(0, q)
|
||||||
call assert_fails('lrewind', 'E924:')
|
call assert_fails('lrewind', 'E924:')
|
||||||
|
|
||||||
@@ -625,14 +625,14 @@ function XquickfixChangedByAutocmd(cchar)
|
|||||||
let Xgetexpr = a:cchar . 'getexpr'
|
let Xgetexpr = a:cchar . 'getexpr'
|
||||||
let Xrewind = a:cchar . 'rewind'
|
let Xrewind = a:cchar . 'rewind'
|
||||||
if a:cchar == 'c'
|
if a:cchar == 'c'
|
||||||
let Xsetlist = 'setqflist('
|
let Xsetlist = function('setqflist')
|
||||||
let ErrorNr = 'E925'
|
let ErrorNr = 'E925'
|
||||||
function! ReadFunc()
|
function! ReadFunc()
|
||||||
colder
|
colder
|
||||||
cgetexpr []
|
cgetexpr []
|
||||||
endfunc
|
endfunc
|
||||||
else
|
else
|
||||||
let Xsetlist = 'setloclist(0,'
|
let Xsetlist = function('setloclist', [0])
|
||||||
let ErrorNr = 'E926'
|
let ErrorNr = 'E926'
|
||||||
function! ReadFunc()
|
function! ReadFunc()
|
||||||
lolder
|
lolder
|
||||||
@@ -642,15 +642,15 @@ function XquickfixChangedByAutocmd(cchar)
|
|||||||
|
|
||||||
augroup testgroup
|
augroup testgroup
|
||||||
au!
|
au!
|
||||||
autocmd BufReadCmd t call ReadFunc()
|
autocmd BufReadCmd test_changed.txt call ReadFunc()
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
bwipe!
|
new | only
|
||||||
let words = [ "a", "b" ]
|
let words = [ "a", "b" ]
|
||||||
let qflist = []
|
let qflist = []
|
||||||
for word in words
|
for word in words
|
||||||
call add(qflist, {'filename': 't'})
|
call add(qflist, {'filename': 'test_changed.txt'})
|
||||||
exec "call " . Xsetlist . "qflist, '')"
|
call Xsetlist(qflist, ' ')
|
||||||
endfor
|
endfor
|
||||||
exec "call assert_fails('" . Xrewind . "', '" . ErrorNr . ":')"
|
exec "call assert_fails('" . Xrewind . "', '" . ErrorNr . ":')"
|
||||||
|
|
||||||
@@ -727,3 +727,89 @@ function Test_setqflist()
|
|||||||
|
|
||||||
call delete('Xtestfile')
|
call delete('Xtestfile')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! XquickfixSetListWithAct(cchar)
|
||||||
|
let Xolder = a:cchar . 'older'
|
||||||
|
let Xnewer = a:cchar . 'newer'
|
||||||
|
if a:cchar == 'c'
|
||||||
|
let Xsetlist = function('setqflist')
|
||||||
|
let Xgetlist = function('getqflist')
|
||||||
|
else
|
||||||
|
let Xsetlist = function('setloclist', [0])
|
||||||
|
let Xgetlist = function('getloclist', [0])
|
||||||
|
endif
|
||||||
|
let list1 = [{'filename': 'fnameA', 'text': 'A'},
|
||||||
|
\ {'filename': 'fnameB', 'text': 'B'}]
|
||||||
|
let list2 = [{'filename': 'fnameC', 'text': 'C'},
|
||||||
|
\ {'filename': 'fnameD', 'text': 'D'},
|
||||||
|
\ {'filename': 'fnameE', 'text': 'E'}]
|
||||||
|
|
||||||
|
" {action} is unspecified. Same as specifing ' '.
|
||||||
|
new | only
|
||||||
|
exec "silent! " . Xnewer . "99"
|
||||||
|
call Xsetlist(list1)
|
||||||
|
call Xsetlist(list2)
|
||||||
|
let li = Xgetlist()
|
||||||
|
call assert_equal(3, len(li))
|
||||||
|
call assert_equal('C', li[0]['text'])
|
||||||
|
call assert_equal('D', li[1]['text'])
|
||||||
|
call assert_equal('E', li[2]['text'])
|
||||||
|
exec "silent! " . Xolder
|
||||||
|
let li = Xgetlist()
|
||||||
|
call assert_equal(2, len(li))
|
||||||
|
call assert_equal('A', li[0]['text'])
|
||||||
|
call assert_equal('B', li[1]['text'])
|
||||||
|
|
||||||
|
" {action} is specified ' '.
|
||||||
|
new | only
|
||||||
|
exec "silent! " . Xnewer . "99"
|
||||||
|
call Xsetlist(list1)
|
||||||
|
call Xsetlist(list2, ' ')
|
||||||
|
let li = Xgetlist()
|
||||||
|
call assert_equal(3, len(li))
|
||||||
|
call assert_equal('C', li[0]['text'])
|
||||||
|
call assert_equal('D', li[1]['text'])
|
||||||
|
call assert_equal('E', li[2]['text'])
|
||||||
|
exec "silent! " . Xolder
|
||||||
|
let li = Xgetlist()
|
||||||
|
call assert_equal(2, len(li))
|
||||||
|
call assert_equal('A', li[0]['text'])
|
||||||
|
call assert_equal('B', li[1]['text'])
|
||||||
|
|
||||||
|
" {action} is specified 'a'.
|
||||||
|
new | only
|
||||||
|
exec "silent! " . Xnewer . "99"
|
||||||
|
call Xsetlist(list1)
|
||||||
|
call Xsetlist(list2, 'a')
|
||||||
|
let li = Xgetlist()
|
||||||
|
call assert_equal(5, len(li))
|
||||||
|
call assert_equal('A', li[0]['text'])
|
||||||
|
call assert_equal('B', li[1]['text'])
|
||||||
|
call assert_equal('C', li[2]['text'])
|
||||||
|
call assert_equal('D', li[3]['text'])
|
||||||
|
call assert_equal('E', li[4]['text'])
|
||||||
|
|
||||||
|
" {action} is specified 'r'.
|
||||||
|
new | only
|
||||||
|
exec "silent! " . Xnewer . "99"
|
||||||
|
call Xsetlist(list1)
|
||||||
|
call Xsetlist(list2, 'r')
|
||||||
|
let li = Xgetlist()
|
||||||
|
call assert_equal(3, len(li))
|
||||||
|
call assert_equal('C', li[0]['text'])
|
||||||
|
call assert_equal('D', li[1]['text'])
|
||||||
|
call assert_equal('E', li[2]['text'])
|
||||||
|
|
||||||
|
" Test for wrong value.
|
||||||
|
new | only
|
||||||
|
call assert_fails("call Xsetlist(0)", 'E714:')
|
||||||
|
call assert_fails("call Xsetlist(list1, '')", 'E927:')
|
||||||
|
call assert_fails("call Xsetlist(list1, 'aa')", 'E927:')
|
||||||
|
call assert_fails("call Xsetlist(list1, ' a')", 'E927:')
|
||||||
|
call assert_fails("call Xsetlist(list1, 0)", 'E928:')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
function Test_quickfix_set_list_with_act()
|
||||||
|
call XquickfixSetListWithAct('c')
|
||||||
|
call XquickfixSetListWithAct('l')
|
||||||
|
endfunction
|
||||||
|
@@ -672,7 +672,7 @@ static int included_patches[] = {
|
|||||||
// 1771 NA
|
// 1771 NA
|
||||||
// 1770 NA
|
// 1770 NA
|
||||||
// 1769,
|
// 1769,
|
||||||
// 1768,
|
1768,
|
||||||
// 1767 NA
|
// 1767 NA
|
||||||
// 1766 NA
|
// 1766 NA
|
||||||
1765,
|
1765,
|
||||||
|
@@ -18,9 +18,9 @@ describe('setqflist()', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('requires a string for {action}', function()
|
it('requires a string for {action}', function()
|
||||||
eq('Vim(call):E114: String required', exc_exec('call setqflist([], 5)'))
|
eq('Vim(call):E928: String required', exc_exec('call setqflist([], 5)'))
|
||||||
eq('Vim(call):E114: String required', exc_exec('call setqflist([], [])'))
|
eq('Vim(call):E928: String required', exc_exec('call setqflist([], [])'))
|
||||||
eq('Vim(call):E114: String required', exc_exec('call setqflist([], {})'))
|
eq('Vim(call):E928: String required', exc_exec('call setqflist([], {})'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('sets w:quickfix_title', function()
|
it('sets w:quickfix_title', function()
|
||||||
@@ -56,9 +56,9 @@ describe('setloclist()', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('requires a string for {action}', function()
|
it('requires a string for {action}', function()
|
||||||
eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], 5)'))
|
eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], 5)'))
|
||||||
eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], [])'))
|
eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], [])'))
|
||||||
eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], {})'))
|
eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], {})'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('sets w:quickfix_title for the correct window', function()
|
it('sets w:quickfix_title for the correct window', function()
|
||||||
|
Reference in New Issue
Block a user