From aecd91aedc62e27110bed5fddb5e1efc40d47ec7 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 18 Apr 2023 16:49:57 +0330 Subject: [PATCH] Shell: Correctly handle escaped quote characters in strings Previously "foo\`bar" was treated literally, but \` is a valid escape character. This commit makes that string correctly evaluate as "foo`bar". --- Userland/Shell/PosixParser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Shell/PosixParser.cpp b/Userland/Shell/PosixParser.cpp index 1c6fb1832a..748816fc88 100644 --- a/Userland/Shell/PosixParser.cpp +++ b/Userland/Shell/PosixParser.cpp @@ -1685,6 +1685,10 @@ ErrorOr> Parser::parse_word() switch (ch) { case '\\': if (!escape && i + 1 < string.length()) { + if (run_start.has_value()) + TRY(append_string_literal(string.substring_view(*run_start, i - *run_start))); + run_start = i + 1; + if (is_one_of(string[i + 1], '"', '\'', '$', '`', '\\')) { escape = in_quote != Quote::Single; continue;