Compare commits

...

5 Commits

Author SHA1 Message Date
Martin Tournoij
4a82bdfaa8 patch 9.0.2011: INI files not detected
Problem:  INI files not detected
Solution: detect uppercase .INI as dosini files

It previo~1 only worked for lower-case .ini files, but upperc~1 .INI is
also somewhat common on account of DOS' old 8.3 upperc~2 only filena~1.

closes: #13316

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Martin Tournoij <martin@arp242.net>
2023-10-11 21:20:06 +02:00
Christian Brabandt
41e6f7d6ba patch 9.0.2010: [security] use-after-free from buf_contents_changed()
Problem:  [security] use-after-free from buf_contents_changed()
Solution: block autocommands

Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-10-11 21:09:53 +02:00
Yee Cheng Chin
54844857fd patch 9.0.2009: cmdline-completion for comma-separated options wrong
Problem:  cmdline-completion for comma-separated options wrong
Solution: Fix command-line expansions for options with filenames with
          commas

Fix command-line expansions for options with filenames with commas

Cmdline expansion for option values that take a comma-separated list
of file names is currently not handling file names with commas as the
commas are not escaped. For such options, the commas in file names need
to be escaped (to differentiate from a comma that delimit the list
items). The escaped comma is unescaped in `copy_option_part()` during
option parsing.

Fix as follows:
- Cmdline completion for option values with comma-separated file/folder
  names will not start a new match when seeing `\\,` and will instead
  consider it as one value.
- File/folder regex matching will strip the `\\` when seeing `\\,` to
  make sure it can match the correct files/folders.
- The expanded value will escape `,` with `\\,`, similar to how spaces
  are escaped to make sure the option value is correct on the cmdline.

This fix also takes into account the fact that Win32 Vim handles file
name escaping differently. Typing '\,' for a file name results in it
being handled literally but in other platforms '\,' is interpreted as a
simple ',' and commas need to be escaped using '\\,' instead.

Also, make sure this new logic only applies to comma-separated options
like 'path'. Non-list options like 'set makeprg=<Tab>' and regular ex
commands like `:edit <Tab>` do not require escaping and will continue to
work.

Also fix up documentation to be clearer. The original docs are slightly
misleading in how it discusses triple slashes for 'tags'.

closes: #13303
related: #13301

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2023-10-09 18:12:31 +02:00
Dominique Pellé
b07b9dc4da patch 9.0.2008: test: undofile left behind
Problem:  test: undofile left behind
Solution: cleanup undofile

fix: tmp file not deleted when running make test_undo

Temporary file `.Xtestfile.txt.un~` was left running `make test_undo`
and vim was configured with:
```
./configure --with-features=normal --enable-gui=no --enable-terminal
```

closes: #13304

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Dominique Pellé <dominique.pelle@tomtom.com>
2023-10-09 18:09:20 +02:00
Yegappan Lakshmanan
e467189022 patch 9.0.2007: Vim9: covariant parameter types allowed
Problem:  Vim9: covariant parameter types allowed when assigning
          functions
Solution: Enforce invariant type check for arguments and return value
          when assigning a funcref

closes: #13299
closes: #13305

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-10-09 18:01:06 +02:00
15 changed files with 232 additions and 24 deletions

View File

@@ -192,10 +192,27 @@ To include white space in a string option value it has to be preceded with a
backslash. To include a backslash you have to use two. Effectively this
means that the number of backslashes in an option value is halved (rounded
down).
In options 'path', 'cdpath', and 'tags', spaces have to be preceded with three
backslashes instead for compatibility with version 3.0 where the options can
be separated by either commas or spaces.
Comma-separated options like 'backupdir' and 'tags' will also require commas
to be escaped with two backslashes, whereas this is not needed for
non-comma-separated ones like 'makeprg'.
When setting options using |:let| and |literal-string|, you need to use one
fewer layer of backslash.
A few examples: >
:set tags=tags\ /usr/tags results in "tags /usr/tags"
:set tags=tags\\,file results in "tags\,file"
:set tags=tags\\\ file results in "tags\ file"
:set makeprg=make\ file results in "make file"
:let &makeprg='make file' (same as above)
:set makeprg=make\\\ file results in "make\ file"
:set tags=tags\ /usr/tags results in "tags" and "/usr/tags"
:set tags=tags\\\ file results in "tags file"
:let &tags='tags\ file' (same as above)
:set makeprg=make,file results in "make,file"
:set makeprg=make\\,file results in "make\,file"
:set tags=tags,file results in "tags" and "file"
:set tags=tags\\,file results in "tags,file"
:let &tags='tags\,file' (same as above)
The "|" character separates a ":set" command from a following command. To
include the "|" in the option value, use "\|" instead. This example sets the
@@ -8213,8 +8230,8 @@ A jump table for the options with a short description can be found at |Q_op|.
|+emacs_tags|: "./tags,./TAGS,tags,TAGS")
global or local to buffer |global-local|
Filenames for the tag command, separated by spaces or commas. To
include a space or comma in a file name, precede it with a backslash
(see |option-backslash| about including spaces and backslashes).
include a space or comma in a file name, precede it with backslashes
(see |option-backslash| about including spaces/commas and backslashes).
When a file name starts with "./", the '.' is replaced with the path
of the current file. But only when the 'd' flag is not included in
'cpoptions'. Environment variables are expanded |:set_env|. Also see

View File

@@ -1013,7 +1013,7 @@ au BufNewFile,BufRead ipf.conf,ipf6.conf,ipf.rules setf ipfilter
au BufNewFile,BufRead *.4gl,*.4gh,*.m4gl setf fgl
" .INI file for MSDOS
au BufNewFile,BufRead *.ini setf dosini
au BufNewFile,BufRead *.ini,*.INI setf dosini
" SysV Inittab
au BufNewFile,BufRead inittab setf inittab

View File

@@ -6013,6 +6013,9 @@ buf_contents_changed(buf_T *buf)
return TRUE;
}
// We don't want to trigger autocommands now, they may have nasty
// side-effects like wiping buffers
block_autocmds();
if (ml_open(curbuf) == OK
&& readfile(buf->b_ffname, buf->b_fname,
(linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
@@ -6038,6 +6041,8 @@ buf_contents_changed(buf_T *buf)
if (curbuf != newbuf) // safety check
wipe_buffer(newbuf, FALSE);
unblock_autocmds();
return differ;
}

View File

@@ -113,9 +113,10 @@ wildescape(
for (int i = 0; i < numfiles; ++i)
{
// for ":set path=" we need to escape spaces twice
if (xp->xp_backslash == XP_BS_THREE)
if (xp->xp_backslash & XP_BS_THREE)
{
p = vim_strsave_escaped(files[i], (char_u *)" ");
char *pat = (xp->xp_backslash & XP_BS_COMMA) ? " ," : " ";
p = vim_strsave_escaped(files[i], (char_u *)pat);
if (p != NULL)
{
vim_free(files[i]);
@@ -130,6 +131,18 @@ wildescape(
#endif
}
}
else if (xp->xp_backslash & XP_BS_COMMA)
{
if (vim_strchr(files[i], ',') != NULL)
{
p = vim_strsave_escaped(files[i], (char_u *)",");
if (p != NULL)
{
vim_free(files[i]);
files[i] = p;
}
}
}
#ifdef BACKSLASH_IN_FILENAME
p = vim_strsave_fnameescape(files[i], vse_what);
#else
@@ -2730,14 +2743,23 @@ expand_files_and_dirs(
for (i = 0; pat[i]; ++i)
if (pat[i] == '\\')
{
if (xp->xp_backslash == XP_BS_THREE
if (xp->xp_backslash & XP_BS_THREE
&& pat[i + 1] == '\\'
&& pat[i + 2] == '\\'
&& pat[i + 3] == ' ')
STRMOVE(pat + i, pat + i + 3);
if (xp->xp_backslash == XP_BS_ONE
else if (xp->xp_backslash & XP_BS_ONE
&& pat[i + 1] == ' ')
STRMOVE(pat + i, pat + i + 1);
else if ((xp->xp_backslash & XP_BS_COMMA)
&& pat[i + 1] == '\\'
&& pat[i + 2] == ',')
STRMOVE(pat + i, pat + i + 2);
#ifdef BACKSLASH_IN_FILENAME
else if ((xp->xp_backslash & XP_BS_COMMA)
&& pat[i + 1] == ',')
STRMOVE(pat + i, pat + i + 1);
#endif
}
}

View File

@@ -7451,6 +7451,8 @@ set_context_in_set_cmd(
else
xp->xp_backslash = XP_BS_ONE;
}
if (flags & P_COMMA)
xp->xp_backslash |= XP_BS_COMMA;
}
// For an option that is a list of file names, or comma/colon-separated
@@ -7469,8 +7471,12 @@ set_context_in_set_cmd(
s = p;
while (s > xp->xp_pattern && *(s - 1) == '\\')
--s;
if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
|| (*p == ',' && (flags & P_COMMA) && ((p - s) % 1) == 0)
if ((*p == ' ' && ((xp->xp_backslash & XP_BS_THREE) && (p - s) < 3))
#if defined(BACKSLASH_IN_FILENAME)
|| (*p == ',' && (flags & P_COMMA) && (p - s) < 1)
#else
|| (*p == ',' && (flags & P_COMMA) && (p - s) < 2)
#endif
|| (*p == ':' && (flags & P_COLON)))
{
xp->xp_pattern = p + 1;

View File

@@ -631,8 +631,9 @@ typedef struct expand
* values for xp_backslash
*/
#define XP_BS_NONE 0 // nothing special for backslashes
#define XP_BS_ONE 1 // uses one backslash before a space
#define XP_BS_THREE 2 // uses three backslashes before a space
#define XP_BS_ONE 0x1 // uses one backslash before a space
#define XP_BS_THREE 0x2 // uses three backslashes before a space
#define XP_BS_COMMA 0x4 // commas need to be escaped with a backslash
/*
* Variables shared between getcmdline(), redrawcmdline() and others.

Binary file not shown.

View File

@@ -1257,13 +1257,71 @@ func Test_cmdline_complete_various()
mapclear
delcom MyCmd
" Prepare for path completion
call mkdir('Xa b c', 'D')
defer delete('Xcomma,foobar.txt')
call writefile([], 'Xcomma,foobar.txt')
" completion for :set path= with multiple backslashes
call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set path=a\\\ b', @:)
call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
set path&
" completion for :set dir= with a backslash
call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set dir=a\ b', @:)
call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set dir=Xa\ b\ c/', @:)
set dir&
" completion for :set tags= / set dictionary= with escaped commas
if has('win32')
" In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
" '\,'
call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
" completion for :set dictionary= with escaped commas (same behavior, but
" different internal code path from 'set tags=' for escaping the output)
call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
else
" In other platforms, backslashes are rounded down (since '\,' itself will
" be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
" completion for :set dictionary= with escaped commas (same behavior, but
" different internal code path from 'set tags=' for escaping the output)
call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
endif
set tags&
set dictionary&
" completion for :set makeprg= with no escaped commas
call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
if !has('win32')
" Cannot create file with backslash in file name in Windows, so only test
" this elsewhere.
defer delete('Xcomma\,fooslash.txt')
call writefile([], 'Xcomma\,fooslash.txt')
call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
endif
set makeprg&
" completion for the :py3 commands
call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')

View File

@@ -78,6 +78,14 @@ func Test_crash1()
\ ' && echo "crash 9: [OK]" >> X_crash1_result.txt' .. "\<cr>")
call TermWait(buf, 1000)
let file = 'crash/editing_arg_idx_POC_1'
let args = printf(cmn_args, vim, file)
call term_sendkeys(buf, args ..
\ ' || echo "crash 10: [OK]" >> X_crash1_result.txt' .. "\<cr>")
call TermWait(buf, 1000)
call delete('Xerr')
call delete('@')
" clean up
exe buf .. "bw!"
@@ -93,6 +101,7 @@ func Test_crash1()
\ 'crash 7: [OK]',
\ 'crash 8: [OK]',
\ 'crash 9: [OK]',
\ 'crash 10: [OK]',
\ ]
call assert_equal(expected, getline(1, '$'))

View File

@@ -206,7 +206,7 @@ def s:GetFilenameChecks(): dict<list<string>>
dnsmasq: ['/etc/dnsmasq.conf', '/etc/dnsmasq.d/file', 'any/etc/dnsmasq.conf', 'any/etc/dnsmasq.d/file'],
dockerfile: ['Containerfile', 'Dockerfile', 'dockerfile', 'file.Dockerfile', 'file.dockerfile', 'Dockerfile.debian', 'Containerfile.something'],
dosbatch: ['file.bat'],
dosini: ['/etc/yum.conf', 'file.ini', 'npmrc', '.npmrc', 'php.ini', 'php.ini-5', 'php.ini-file', '/etc/yum.repos.d/file', 'any/etc/yum.conf', 'any/etc/yum.repos.d/file', 'file.wrap', 'file.vbp'],
dosini: ['/etc/yum.conf', 'file.ini', 'npmrc', '.npmrc', 'php.ini', 'php.ini-5', 'php.ini-file', '/etc/yum.repos.d/file', 'any/etc/yum.conf', 'any/etc/yum.repos.d/file', 'file.wrap', 'file.vbp', 'ja2.ini', 'JA2.INI'],
dot: ['file.dot', 'file.gv'],
dracula: ['file.drac', 'file.drc', 'filelvs', 'filelpe', 'drac.file', 'lpe', 'lvs', 'some-lpe', 'some-lvs'],
dtd: ['file.dtd'],

View File

@@ -314,6 +314,7 @@ func Test_set_completion()
call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_match(' ./samples/ ', @:)
call assert_notmatch(' ./summarize.vim ', @:)
set cdpath&
" Expand files and directories.
call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
@@ -321,7 +322,50 @@ func Test_set_completion()
call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
set tags&
" Expand files with spaces/commas in them. Make sure we delimit correctly.
"
" 'tags' allow for for spaces/commas to both act as delimiters, with actual
" spaces requiring double escape, and commas need a single escape.
" 'dictionary' is a normal comma-separated option where only commas act as
" delimiters, and both space/comma need one single escape.
" 'makeprg' is a non-comma-separated option. Commas don't need escape.
defer delete('Xfoo Xspace.txt')
defer delete('Xsp_dummy')
defer delete('Xbar,Xcomma.txt')
defer delete('Xcom_dummy')
call writefile([], 'Xfoo Xspace.txt')
call writefile([], 'Xsp_dummy')
call writefile([], 'Xbar,Xcomma.txt')
call writefile([], 'Xcom_dummy')
call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
if has('win32')
" In Windows, '\,' is literal, see `:help filename-backslash`, so this
" means we treat it as one file name.
call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
else
" In other platforms, '\,' simply escape to ',', and indicate a delimiter
" to split into a separate file name. You need '\\,' to escape the comma
" as part of the file name.
call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
endif
call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
set tags& dictionary& makeprg&
" Expanding the option names
call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')

View File

@@ -860,6 +860,7 @@ func Test_undo_after_write()
call StopVimInTerminal(buf)
call delete('Xtestfile.txt')
call delete('.Xtestfile.txt.un~')
endfunc
func Test_undo_range_normal()

View File

@@ -7154,4 +7154,41 @@ def Test_recursive_class_method_call()
v9.CheckSourceSuccess(lines)
enddef
" Test for checking the argument types and the return type when assigning a
" funcref to make sure the invariant class type is used.
def Test_funcref_argtype_returntype_check()
var lines =<< trim END
vim9script
class A
endclass
class B extends A
endclass
def Foo(p: B): B
return B.new()
enddef
var Bar: func(A): A = Foo
END
v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 11)
lines =<< trim END
vim9script
class A
endclass
class B extends A
endclass
def Foo(p: B): B
return B.new()
enddef
def Baz()
var Bar: func(A): A = Foo
enddef
Baz()
END
v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 1)
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

View File

@@ -704,6 +704,16 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2011,
/**/
2010,
/**/
2009,
/**/
2008,
/**/
2007,
/**/
2006,
/**/

View File

@@ -874,8 +874,7 @@ check_type_maybe(
{
where_T func_where = where;
if (where.wt_kind == WT_METHOD)
func_where.wt_kind = WT_METHOD_RETURN;
func_where.wt_kind = WT_METHOD_RETURN;
ret = check_type_maybe(expected->tt_member,
actual->tt_member, FALSE,
func_where);
@@ -898,8 +897,7 @@ check_type_maybe(
&& i < actual->tt_argcount; ++i)
{
where_T func_where = where;
if (where.wt_kind == WT_METHOD)
func_where.wt_kind = WT_METHOD_ARG;
func_where.wt_kind = WT_METHOD_ARG;
// Allow for using "any" argument type, lambda's have them.
if (actual->tt_args[i] != &t_any && check_type(