robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:partial:9.2.0736: potential command execution in PHP omni-completion (#40445)6a61c81e31

master
1.3 KiB35 linesraw
1" Tests for the PHP omni-completion plugin (runtime/autoload/phpcomplete.vim).
2
3" A buffer class name is interpolated into a search() pattern run via
4" win_execute().  Without escaping, "'" closes the string and "|" starts a new
5" Ex command, so the name runs as an Ex command during completion.
6func Test_phpcomplete_no_exec_via_class_name()
7  unlet! g:phpcomplete_injected
8  let lines = ['<?php', 'class x {}', '']
9  let payload = "x')|let g:phpcomplete_injected = 1|call search('"
10
11  try
12    call phpcomplete#GetClassContentsStructure('x.php', lines, payload)
13  catch
14  endtry
15
16  call assert_false(exists('g:phpcomplete_injected'),
17        \ 'class name was executed as an Ex command during completion')
18
19  unlet! g:phpcomplete_injected
20endfunc
21
22func Test_phpcomplete_class_lookup_still_works()
23  let lines = ['<?php', 'class Foo {', '    public $bar;', '}', '']
24  let result = phpcomplete#GetClassContentsStructure('Foo.php', lines, 'Foo')
25
26  call assert_equal(type([]), type(result),
27        \ 'GetClassContentsStructure did not return a list')
28  call assert_true(len(result) > 0, 'no class structure returned')
29  call assert_match('class Foo', result[0].content,
30        \ 'class body missing from returned content')
31  call assert_match('bar', result[0].content,
32        \ 'class member missing from returned content')
33endfunc
34
35" vim: shiftwidth=2 sts=2 expandtab