1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

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.
This commit is contained in:
Ali Mohammad Pur 2023-09-21 02:32:09 +03:30 committed by Jelle Raaijmakers
parent 21ea9cedff
commit 9e978c6cd1

View file

@ -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::ReductionResult> 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);