mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
Treat comments ending in backslashes as not continuing onto the next line
Fixes #1255
This commit is contained in:
parent
c59119e0b7
commit
3ca518255e
3 changed files with 34 additions and 2 deletions
25
reader.cpp
25
reader.cpp
|
@ -3065,6 +3065,18 @@ static wchar_t unescaped_quote(const wcstring &str, size_t pos)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* Returns true if the last token is a comment. */
|
||||
static bool text_ends_in_comment(const wcstring &text)
|
||||
{
|
||||
token_type last_type = TOK_NONE;
|
||||
tokenizer_t tok(text.c_str(), TOK_ACCEPT_UNFINISHED | TOK_SHOW_COMMENTS | TOK_SQUASH_ERRORS);
|
||||
while (tok_has_next(&tok))
|
||||
{
|
||||
last_type = tok_last_type(&tok);
|
||||
tok_next(&tok);
|
||||
}
|
||||
return last_type == TOK_COMMENT;
|
||||
}
|
||||
|
||||
const wchar_t *reader_readline(int nchars)
|
||||
{
|
||||
|
@ -3561,10 +3573,19 @@ const wchar_t *reader_readline(int nchars)
|
|||
/* We only execute the command line */
|
||||
editable_line_t *el = &data->command_line;
|
||||
|
||||
/* Allow backslash-escaped newlines, but only if the following character is whitespace, or we're at the end of the text (see issue #613) */
|
||||
/* Allow backslash-escaped newlines, but only if the following character is whitespace, or we're at the end of the text (see issue #613) and not in a comment (#1255). */
|
||||
if (is_backslashed(el->text, el->position))
|
||||
{
|
||||
if (el->position >= el->size() || iswspace(el->text.at(el->position)))
|
||||
bool continue_on_next_line = false;
|
||||
if (el->position >= el->size())
|
||||
{
|
||||
continue_on_next_line = ! text_ends_in_comment(el->text);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue_on_next_line = iswspace(el->text.at(el->position));
|
||||
}
|
||||
if (continue_on_next_line)
|
||||
{
|
||||
insert_char(el, '\n');
|
||||
break;
|
||||
|
|
|
@ -33,3 +33,9 @@ send_line $hist_command
|
|||
expect_prompt -re {echo .history.*} {} unmatched {
|
||||
puts stderr "Couldn't find expected output $hist_command"
|
||||
}
|
||||
|
||||
# Backslashes at end of comments (#1255)
|
||||
# This backslash should NOT cause the line to continue
|
||||
send_line "echo -n #comment\\"
|
||||
expect_prompt
|
||||
|
||||
|
|
|
@ -155,6 +155,11 @@ echo before comment \
|
|||
# comment
|
||||
after comment
|
||||
|
||||
# Backslashes are part of comments and do not join lines (#1255)
|
||||
# This should execute false, not echo it
|
||||
echo -n # comment\
|
||||
false
|
||||
|
||||
function always_fails
|
||||
if true
|
||||
return 1
|
||||
|
|
Loading…
Reference in a new issue