Merge pull request #12395 from Rylan12/fix-relocation-regex

`Keg::Relocation`: allow `-F`, `-I`, `-L`, `-isystem` prefixes
This commit is contained in:
Rylan Polster 2021-11-08 20:39:41 -05:00 committed by GitHub
commit 0730fa74f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -12,7 +12,7 @@ class Keg
class Relocation
extend T::Sig
RELOCATABLE_PATH_REGEX_PREFIX = /(?<![a-zA-Z0-9])/.freeze
RELOCATABLE_PATH_REGEX_PREFIX = /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))/.freeze
def initialize
@replacement_map = {}

View File

@ -12,8 +12,8 @@ describe Keg::Relocation do
let(:cellar_placeholder) { "@@HOMEBREW_CELLAR@@" }
let(:repository_placeholder) { "@@HOMEBREW_REPOSITORY@@" }
let(:library_placeholder) { "@@HOMEBREW_LIBRARY@@" }
let(:escaped_prefix) { /(?<![a-zA-Z0-9])#{Regexp.escape(HOMEBREW_PREFIX)}/o }
let(:escaped_cellar) { /(?<![a-zA-Z0-9])#{HOMEBREW_CELLAR}/o }
let(:escaped_prefix) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{Regexp.escape(HOMEBREW_PREFIX)}/o }
let(:escaped_cellar) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{HOMEBREW_CELLAR}/o }
def setup_relocation
relocation = described_class.new
@ -61,8 +61,8 @@ describe Keg::Relocation do
specify "::path_to_regex" do
expect(described_class.path_to_regex(prefix)).to eq escaped_prefix
expect(described_class.path_to_regex("foo.bar")).to eq(/(?<![a-zA-Z0-9])foo\.bar/)
expect(described_class.path_to_regex("foo.bar")).to eq(/(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))foo\.bar/)
expect(described_class.path_to_regex(/#{cellar}/o)).to eq escaped_cellar
expect(described_class.path_to_regex(/foo.bar/)).to eq(/(?<![a-zA-Z0-9])foo.bar/)
expect(described_class.path_to_regex(/foo.bar/)).to eq(/(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))foo.bar/)
end
end