From a1410cb5da66b6dc8afa30c0ac35afe1a4313ae6 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 2 Feb 2026 21:13:31 -0800 Subject: [PATCH] Clean up command substitution escapes --- ruby/shell/word_expander.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ruby/shell/word_expander.rb b/ruby/shell/word_expander.rb index a995604..48c4170 100644 --- a/ruby/shell/word_expander.rb +++ b/ruby/shell/word_expander.rb @@ -177,11 +177,7 @@ module Shell if i + 1 < line.length escaped = line[i + 1] if escaped == "$" || escaped == "`" || escaped == "\\" || escaped == "\"" - output << (if escaped == "$" - ESCAPED_DOLLAR - else - ((escaped == "`") ? ESCAPED_BACKTICK : escaped) - end) + output << escaped_replacement(escaped) else output << "\\" output << escaped @@ -272,6 +268,17 @@ module Shell stdout.tr("\n", " ") end + def escaped_replacement(char) + case char + when "$" + ESCAPED_DOLLAR + when "`" + ESCAPED_BACKTICK + else + char + end + end + def protect_escaped_dollars(line) output = +"" i = 0