diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 19c00fd885..ea763127d5 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -32,7 +32,7 @@ EOS MAXIMUM_STRING_MATCHES = 100 ALLOWABLE_HOMEBREW_REPOSITORY_LINKS = [ - %r{#{HOMEBREW_LIBRARY}/Homebrew/os/(mac|linux)/pkgconfig}, + %r{#{Regexp.escape(HOMEBREW_LIBRARY)}/Homebrew/os/(mac|linux)/pkgconfig}, ].freeze module Homebrew diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 1993dcccf0..51ac170287 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -131,10 +131,9 @@ class Keg old_prefix, new_prefix = relocation.replacement_pair_for(:prefix) old_cellar, new_cellar = relocation.replacement_pair_for(:cellar) - case old_name - when /^#{old_cellar}/ + if old_name.start_with? old_cellar old_name.sub(old_cellar, new_cellar) - when /^#{old_prefix}/ + elsif old_name.start_with? old_prefix old_name.sub(old_prefix, new_prefix) end end diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index 5c85626844..324b6ffb31 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -24,7 +24,7 @@ class Keg sig { params(key: Symbol, old_value: T.any(String, Regexp), new_value: String, path: T::Boolean).void } def add_replacement_pair(key, old_value, new_value, path: false) - old_value = self.class.path_regex(old_value) if path + old_value = self.class.path_to_regex(old_value) if path @replacement_map[key] = [old_value, new_value] end @@ -49,15 +49,15 @@ class Keg any_changed end - sig { params(value: T.any(String, Regexp)).returns(Regexp) } - def self.path_regex(value) - value = case value + sig { params(path: T.any(String, Regexp)).returns(Regexp) } + def self.path_to_regex(path) + path = case path when String - Regexp.escape(value) + Regexp.escape(path) when Regexp - value.source + path.source end - Regexp.new(RELOCATABLE_PATH_REGEX_PREFIX.source + value) + Regexp.new(RELOCATABLE_PATH_REGEX_PREFIX.source + path) end end @@ -244,7 +244,7 @@ class Keg def self.text_matches_in_file(file, string, ignores, linked_libraries, formula_and_runtime_deps_names) text_matches = [] - path_regex = Relocation.path_regex(string) + path_regex = Relocation.path_to_regex(string) Utils.popen_read("strings", "-t", "x", "-", file.to_s) do |io| until io.eof? str = io.readline.chomp diff --git a/Library/Homebrew/test/keg_relocate/relocation_spec.rb b/Library/Homebrew/test/keg_relocate/relocation_spec.rb index ff0838c907..c4e0e43a69 100644 --- a/Library/Homebrew/test/keg_relocate/relocation_spec.rb +++ b/Library/Homebrew/test/keg_relocate/relocation_spec.rb @@ -59,10 +59,10 @@ describe Keg::Relocation do REPLACED end - specify "::path_regex" do - expect(described_class.path_regex(prefix)).to eq escaped_prefix - expect(described_class.path_regex("foo.bar")).to eq(/(?