From 9e978c6cd1bf3b2692e44f246b904927b4982d03 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 21 Sep 2023 02:32:09 +0330 Subject: [PATCH] Shell: Recognise the (seemingly) bash-specific <<\WORD heredoc key Bash eats the backslash in this format (similarly for W\ORD etc.). Dr.POSIX doesn't specify this anywhere, but it's used all over the place, so let's support it. --- Userland/Shell/PosixLexer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Shell/PosixLexer.cpp b/Userland/Shell/PosixLexer.cpp index 848d9e891b..a9ccbcbb58 100644 --- a/Userland/Shell/PosixLexer.cpp +++ b/Userland/Shell/PosixLexer.cpp @@ -168,7 +168,8 @@ Lexer::HeredocKeyResult Lexer::process_heredoc_key(Token const& token) } break; default: - if (escaped) { + // NOTE: bash eats the backslash outside quotes :shrug: + if (escaped && parse_state.last() != Free) { builder.append('\\'); escaped = false; } @@ -568,6 +569,8 @@ ErrorOr Lexer::reduce_start() auto contents = m_lexer.input().substring_view(start_index, end_index.value_or(m_lexer.tell()) - start_index); reconsume(contents); + if (end_index.has_value()) + reconsume(m_lexer.input().substring_view_starting_after_substring(contents).substring_view(0, m_lexer.tell() - *end_index)); m_state.buffer.clear(); m_state.buffer.append(contents);