From 52ef7cb7f526d2c92fd8483cb981f1f5dc0aebf5 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 2 Feb 2026 20:42:32 -0800 Subject: [PATCH] Fix tilde user expansion --- ruby/shell/word_expander.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ruby/shell/word_expander.rb b/ruby/shell/word_expander.rb index aaf30a3..ca053f1 100644 --- a/ruby/shell/word_expander.rb +++ b/ruby/shell/word_expander.rb @@ -68,7 +68,12 @@ module Shell found_glob_char = word && word =~ /[*?\[]/ # must be unquoted # Expand tildes at the beginning of unquoted words. if word && at_word_start - field.sub!(/^~/, Dir.home) + field.sub!(/^~([^\/]*)/) do + user = Regexp.last_match(1) + user.empty? ? Dir.home : Dir.home(user) + rescue ArgumentError + "~#{user}" + end end at_word_start = false if sep