0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 9.1.1074: Strange error when heredoc marker starts with "trim"

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: #16574

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-02-03 18:56:16 +01:00
committed by Christian Brabandt
parent 23da16d3d0
commit 449c2e5454
10 changed files with 64 additions and 14 deletions

View File

@@ -1322,7 +1322,8 @@ get_function_body(
{
// ":python <<" continues until a dot, like ":append"
p = skipwhite(arg + 2);
if (STRNCMP(p, "trim", 4) == 0)
if (STRNCMP(p, "trim", 4) == 0
&& (p[4] == NUL || VIM_ISWHITE(p[4])))
{
// Ignore leading white space.
p = skipwhite(p + 4);
@@ -1367,20 +1368,21 @@ get_function_body(
current_sctx.sc_version = save_sc_version;
if (arg != NULL && STRNCMP(arg, "=<<", 3) == 0)
{
int has_trim = FALSE;
p = skipwhite(arg + 3);
while (TRUE)
{
if (STRNCMP(p, "trim", 4) == 0)
if (STRNCMP(p, "trim", 4) == 0
&& (p[4] == NUL || VIM_ISWHITE(p[4])))
{
// Ignore leading white space.
p = skipwhite(p + 4);
heredoc_trimmedlen = skipwhite(theline) - theline;
heredoc_trimmed = vim_strnsave(theline, heredoc_trimmedlen);
if (heredoc_trimmed == NULL)
heredoc_trimmedlen = 0;
has_trim = TRUE;
continue;
}
if (STRNCMP(p, "eval", 4) == 0)
if (STRNCMP(p, "eval", 4) == 0
&& (p[4] == NUL || VIM_ISWHITE(p[4])))
{
// Ignore leading white space.
p = skipwhite(p + 4);
@@ -1388,6 +1390,13 @@ get_function_body(
}
break;
}
if (has_trim)
{
heredoc_trimmedlen = skipwhite(theline) - theline;
heredoc_trimmed = vim_strnsave(theline, heredoc_trimmedlen);
if (heredoc_trimmed == NULL)
heredoc_trimmedlen = 0;
}
skip_until = vim_strnsave(p, skiptowhite(p) - p);
getline_options = GETLINE_NONE;
is_heredoc = TRUE;