mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
vim-patch:9.1.1074: Strange error when heredoc marker starts with "trim" (#32317)
Problem: Strange error when heredoc marker starts with "trim".
Solution: Check for whitespace after "trim" or "eval" (zeertzjq)
For :python3 etc., a heredoc marker that starts with a lower-case letter
is valid, and when it starts with "trim" it works in a script but not in
a function, and this PR makes it works in a function.
For :let, a heredoc marker that starts with a lower-case letter is not
valid, but when it starts with "trim" or "eval" the error can be a bit
confusing in a function, and this PR make it less confusing.
closes: vim/vim#16574
449c2e5454
This commit is contained in:
@@ -2456,7 +2456,8 @@ static int get_function_body(exarg_T *eap, garray_T *newlines, char *line_arg_in
|
|||||||
&& (!ASCII_ISALPHA(p[2]) || p[2] == 's')))) {
|
&& (!ASCII_ISALPHA(p[2]) || p[2] == 's')))) {
|
||||||
// ":python <<" continues until a dot, like ":append"
|
// ":python <<" continues until a dot, like ":append"
|
||||||
p = skipwhite(arg + 2);
|
p = skipwhite(arg + 2);
|
||||||
if (strncmp(p, "trim", 4) == 0) {
|
if (strncmp(p, "trim", 4) == 0
|
||||||
|
&& (p[4] == NUL || ascii_iswhite(p[4]))) {
|
||||||
// Ignore leading white space.
|
// Ignore leading white space.
|
||||||
p = skipwhite(p + 4);
|
p = skipwhite(p + 4);
|
||||||
heredoc_trimmedlen = (size_t)(skipwhite(theline) - theline);
|
heredoc_trimmedlen = (size_t)(skipwhite(theline) - theline);
|
||||||
@@ -2484,21 +2485,27 @@ static int get_function_body(exarg_T *eap, garray_T *newlines, char *line_arg_in
|
|||||||
}
|
}
|
||||||
if (arg != NULL && strncmp(arg, "=<<", 3) == 0) {
|
if (arg != NULL && strncmp(arg, "=<<", 3) == 0) {
|
||||||
p = skipwhite(arg + 3);
|
p = skipwhite(arg + 3);
|
||||||
|
bool has_trim = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (strncmp(p, "trim", 4) == 0) {
|
if (strncmp(p, "trim", 4) == 0
|
||||||
|
&& (p[4] == NUL || ascii_iswhite(p[4]))) {
|
||||||
// Ignore leading white space.
|
// Ignore leading white space.
|
||||||
p = skipwhite(p + 4);
|
p = skipwhite(p + 4);
|
||||||
heredoc_trimmedlen = (size_t)(skipwhite(theline) - theline);
|
has_trim = true;
|
||||||
heredoc_trimmed = xmemdupz(theline, heredoc_trimmedlen);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp(p, "eval", 4) == 0) {
|
if (strncmp(p, "eval", 4) == 0
|
||||||
|
&& (p[4] == NUL || ascii_iswhite(p[4]))) {
|
||||||
// Ignore leading white space.
|
// Ignore leading white space.
|
||||||
p = skipwhite(p + 4);
|
p = skipwhite(p + 4);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (has_trim) {
|
||||||
|
heredoc_trimmedlen = (size_t)(skipwhite(theline) - theline);
|
||||||
|
heredoc_trimmed = xmemdupz(theline, heredoc_trimmedlen);
|
||||||
|
}
|
||||||
skip_until = xmemdupz(p, (size_t)(skiptowhite(p) - p));
|
skip_until = xmemdupz(p, (size_t)(skiptowhite(p) - p));
|
||||||
do_concat = false;
|
do_concat = false;
|
||||||
is_heredoc = true;
|
is_heredoc = true;
|
||||||
|
|||||||
@@ -436,6 +436,24 @@ func Test_let_heredoc_fails()
|
|||||||
call assert_report('Caught exception: ' .. v:exception)
|
call assert_report('Caught exception: ' .. v:exception)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
try
|
||||||
|
let v =<< trim trimm
|
||||||
|
trimm
|
||||||
|
call assert_report('No exception thrown')
|
||||||
|
catch /E221:/
|
||||||
|
catch
|
||||||
|
call assert_report('Caught exception: ' .. v:exception)
|
||||||
|
endtry
|
||||||
|
|
||||||
|
try
|
||||||
|
let v =<< trim trim evall
|
||||||
|
evall
|
||||||
|
call assert_report('No exception thrown')
|
||||||
|
catch /E221:/
|
||||||
|
catch
|
||||||
|
call assert_report('Caught exception: ' .. v:exception)
|
||||||
|
endtry
|
||||||
|
|
||||||
let text =<< trim END
|
let text =<< trim END
|
||||||
func WrongSyntax()
|
func WrongSyntax()
|
||||||
let v =<< that there
|
let v =<< that there
|
||||||
|
|||||||
@@ -316,7 +316,10 @@ VIM::DoCommand('let s ..= "B"')
|
|||||||
perl << trim eof
|
perl << trim eof
|
||||||
VIM::DoCommand('let s ..= "E"')
|
VIM::DoCommand('let s ..= "E"')
|
||||||
eof
|
eof
|
||||||
call assert_equal('ABCDE', s)
|
perl << trimm
|
||||||
|
VIM::DoCommand('let s ..= "F"')
|
||||||
|
trimm
|
||||||
|
call assert_equal('ABCDEF', s)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
|||||||
@@ -284,7 +284,10 @@ s+='B'
|
|||||||
python3 << trim eof
|
python3 << trim eof
|
||||||
s+='E'
|
s+='E'
|
||||||
eof
|
eof
|
||||||
call assert_equal('ABCDE', pyxeval('s'))
|
python3 << trimm
|
||||||
|
s+='F'
|
||||||
|
trimm
|
||||||
|
call assert_equal('ABCDEF', pyxeval('s'))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
|||||||
@@ -97,7 +97,10 @@ result+='B'
|
|||||||
pyx << trim eof
|
pyx << trim eof
|
||||||
result+='E'
|
result+='E'
|
||||||
eof
|
eof
|
||||||
call assert_equal('ABCDE', pyxeval('result'))
|
pyx << trimm
|
||||||
|
result+='F'
|
||||||
|
trimm
|
||||||
|
call assert_equal('ABCDEF', pyxeval('result'))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
|||||||
@@ -439,7 +439,10 @@ Vim.command('let s ..= "B"')
|
|||||||
ruby << trim eof
|
ruby << trim eof
|
||||||
Vim.command('let s ..= "E"')
|
Vim.command('let s ..= "E"')
|
||||||
eof
|
eof
|
||||||
call assert_equal('ABCDE', s)
|
ruby << trimm
|
||||||
|
Vim.command('let s ..= "F"')
|
||||||
|
trimm
|
||||||
|
call assert_equal('ABCDEF', s)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
|||||||
Reference in New Issue
Block a user