From 6cdc501a75582613b675acd5294ce7d652854c0e Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Tue, 10 Apr 2018 18:15:16 +0800 Subject: [PATCH] Keg#replace_text_in_files: fix incorrect replace order The order of the regexes in `Keg#replace_text_in_files` matters. Otherwise, `/usr/local/Cellar` will be replaced to `@@HOMEBREW_PREFIX@@/Cellar` instead of `@@HOMEBREW_CELLAR@@`. Fixes Homebrew/homebrew-core#26043. --- Library/Homebrew/keg_relocate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index f70bbcbacd..6b996f6708 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -68,7 +68,7 @@ class Keg relocation.old_cellar => relocation.new_cellar, relocation.old_repository => relocation.new_repository, } - changed = s.gsub!(Regexp.union(replacements.keys), replacements) + changed = s.gsub!(Regexp.union(replacements.keys.sort_by(&:length).reverse), replacements) next unless changed changed_files += [first, *rest].map { |file| file.relative_path_from(path) }