From 31598ca8ef54a55117cd84d6e4578973d8c5f1cd Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Tue, 19 Aug 2025 16:29:06 +0800 Subject: [PATCH] diagnostic: improve tilde expansion logic This is a bit pedantic, but the tilde expansion only occurs if the tilde is at the beginning of the string (if we only take the current user into account) [1]. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_06_01 --- Library/Homebrew/diagnostic.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 01aa5d7465..b3493664d9 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -84,7 +84,12 @@ module Homebrew sig { params(path: String).returns(String) } def user_tilde(path) - path.gsub(Dir.home, "~") + home = Dir.home + if path == home + "~" + else + path.gsub(%r{^#{home}/}, "~/") + end end sig { returns(T.nilable(String)) }