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.
This commit is contained in:
Xu Cheng 2018-04-10 18:15:16 +08:00
parent 468210840c
commit 6cdc501a75
No known key found for this signature in database
GPG Key ID: B19F15830AB4E690

View File

@ -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) }