From a6d77162f4539622ca65649b077e244e32974973 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 16 Feb 2023 21:35:39 +0330 Subject: [PATCH] Shell: Correctly keep track of special parameter length We were previously treating special expansions (e.g. $#) as zero-length expansions, which made the shell repeat them literally after expanding them. --- Userland/Shell/PosixLexer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Shell/PosixLexer.cpp b/Userland/Shell/PosixLexer.cpp index a208fcab5d..776856a8a5 100644 --- a/Userland/Shell/PosixLexer.cpp +++ b/Userland/Shell/PosixLexer.cpp @@ -751,7 +751,9 @@ Lexer::ReductionResult Lexer::reduce_special_parameter_expansion() .parameter = StringBuilder {}, .range = range(-1), }; - m_state.expansions.last().get().parameter.append(ch); + auto& expansion = m_state.expansions.last().get(); + expansion.parameter.append(ch); + expansion.range.length = m_state.position.end_offset - expansion.range.start - m_state.position.start_offset; return { .tokens = {},