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
This commit is contained in:
parent
b749cbcffd
commit
31598ca8ef
@ -84,7 +84,12 @@ module Homebrew
|
|||||||
|
|
||||||
sig { params(path: String).returns(String) }
|
sig { params(path: String).returns(String) }
|
||||||
def user_tilde(path)
|
def user_tilde(path)
|
||||||
path.gsub(Dir.home, "~")
|
home = Dir.home
|
||||||
|
if path == home
|
||||||
|
"~"
|
||||||
|
else
|
||||||
|
path.gsub(%r{^#{home}/}, "~/")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(String)) }
|
sig { returns(T.nilable(String)) }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user