mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
fix(heredoc): allow missing end marker for scripts
Also do not crash when getting heredoc fails.
This commit is contained in:
parent
2eb1f62e29
commit
7b6d041bae
@ -163,7 +163,6 @@ char *eval_all_expr_in_str(char *str)
|
||||
list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
|
||||
{
|
||||
char *marker;
|
||||
char *p;
|
||||
int marker_indent_len = 0;
|
||||
int text_indent_len = 0;
|
||||
char *text_indent = NULL;
|
||||
@ -187,7 +186,7 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
|
||||
// The amount of indentation trimmed is the same as the indentation
|
||||
// of the first line after the :let command line. To find the end
|
||||
// marker the indent of the :let command line is trimmed.
|
||||
p = *eap->cmdlinep;
|
||||
char *p = *eap->cmdlinep;
|
||||
while (ascii_iswhite(*p)) {
|
||||
p++;
|
||||
marker_indent_len++;
|
||||
@ -208,7 +207,7 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
|
||||
// The marker is the next word.
|
||||
if (*cmd != NUL && *cmd != '"') {
|
||||
marker = skipwhite(cmd);
|
||||
p = skiptowhite(marker);
|
||||
char *p = skiptowhite(marker);
|
||||
if (*skipwhite(p) != NUL && *skipwhite(p) != '"') {
|
||||
semsg(_(e_trailing_arg), p);
|
||||
return NULL;
|
||||
@ -238,7 +237,9 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
|
||||
xfree(theline);
|
||||
theline = eap->getline(NUL, eap->cookie, 0, false);
|
||||
if (theline == NULL) {
|
||||
semsg(_("E990: Missing end marker '%s'"), marker);
|
||||
if (!script_get) {
|
||||
semsg(_("E990: Missing end marker '%s'"), marker);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -260,7 +261,7 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
|
||||
|
||||
if (text_indent_len == -1 && *theline != NUL) {
|
||||
// set the text indent from the first line.
|
||||
p = theline;
|
||||
char *p = theline;
|
||||
text_indent_len = 0;
|
||||
while (ascii_iswhite(*p)) {
|
||||
p++;
|
||||
|
@ -1619,7 +1619,7 @@ void ex_lua(exarg_T *const eap)
|
||||
{
|
||||
size_t len;
|
||||
char *code = script_get(eap, &len);
|
||||
if (eap->skip) {
|
||||
if (eap->skip || code == NULL) {
|
||||
xfree(code);
|
||||
return;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ local NIL = helpers.NIL
|
||||
local eval = helpers.eval
|
||||
local feed = helpers.feed
|
||||
local clear = helpers.clear
|
||||
local matches = helpers.matches
|
||||
local meths = helpers.meths
|
||||
local exec_lua = helpers.exec_lua
|
||||
local exec_capture = helpers.exec_capture
|
||||
@ -27,22 +28,27 @@ describe(':lua command', function()
|
||||
eq('', exec_capture(
|
||||
'lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})'))
|
||||
eq({'', 'TEST'}, curbufmeths.get_lines(0, 100, false))
|
||||
source(dedent([[
|
||||
source([[
|
||||
lua << EOF
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"})
|
||||
EOF]]))
|
||||
EOF]])
|
||||
eq({'', 'TSET'}, curbufmeths.get_lines(0, 100, false))
|
||||
source(dedent([[
|
||||
source([[
|
||||
lua << EOF
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]]))
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])
|
||||
eq({'', 'SETT'}, curbufmeths.get_lines(0, 100, false))
|
||||
source(dedent([[
|
||||
source([[
|
||||
lua << EOF
|
||||
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
|
||||
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
|
||||
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
|
||||
EOF]]))
|
||||
EOF]])
|
||||
eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false))
|
||||
matches('.*Vim%(lua%):E15: Invalid expression: .*', pcall_err(source, [[
|
||||
lua << eval EOF
|
||||
{}
|
||||
EOF
|
||||
]]))
|
||||
end)
|
||||
it('throws catchable errors', function()
|
||||
eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],
|
||||
|
Loading…
Reference in New Issue
Block a user