Refactor out and correctly create path regex
This commit is contained in:
parent
fd3730a531
commit
fe7f80f647
@ -153,7 +153,9 @@ module Homebrew
|
|||||||
until io.eof?
|
until io.eof?
|
||||||
str = io.readline.chomp
|
str = io.readline.chomp
|
||||||
next if ignores.any? { |i| i =~ str }
|
next if ignores.any? { |i| i =~ str }
|
||||||
next unless str.match? Keg.relocatable_path_regex(string)
|
|
||||||
|
path_regex = Keg::Relocation.path_regex(string)
|
||||||
|
next unless str.match? path_regex
|
||||||
|
|
||||||
offset, match = str.split(" ", 2)
|
offset, match = str.split(" ", 2)
|
||||||
|
|
||||||
@ -162,7 +164,7 @@ module Homebrew
|
|||||||
# Each item in the list should be checked separately
|
# Each item in the list should be checked separately
|
||||||
match.split(":").each do |sub_match|
|
match.split(":").each do |sub_match|
|
||||||
# Not all items in the list may be matches
|
# Not all items in the list may be matches
|
||||||
next unless sub_match.match? Keg.relocatable_path_regex(string)
|
next unless sub_match.match? path_regex
|
||||||
next if linked_libraries.include? sub_match # Don't bother reporting a string if it was found by otool
|
next if linked_libraries.include? sub_match # Don't bother reporting a string if it was found by otool
|
||||||
|
|
||||||
# Do not report matches to files that do not exist.
|
# Do not report matches to files that do not exist.
|
||||||
|
@ -24,7 +24,7 @@ class Keg
|
|||||||
|
|
||||||
sig { params(key: Symbol, old_value: T.any(String, Regexp), new_value: String).void }
|
sig { params(key: Symbol, old_value: T.any(String, Regexp), new_value: String).void }
|
||||||
def add_replacement_pair(key, old_value, new_value)
|
def add_replacement_pair(key, old_value, new_value)
|
||||||
@replacement_map[key] = [path_replacement_regex(old_value), new_value]
|
@replacement_map[key] = [self.class.path_regex(old_value), new_value]
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(key: Symbol).returns(T::Array[T.any(String, Regexp)]) }
|
sig { params(key: Symbol).returns(T::Array[T.any(String, Regexp)]) }
|
||||||
@ -48,10 +48,15 @@ class Keg
|
|||||||
any_changed
|
any_changed
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(text: T.any(String, Regexp)).returns(Regexp) }
|
sig { params(value: T.any(String, Regexp)).returns(Regexp) }
|
||||||
def self.path_replacement_regex(value)
|
def self.path_regex(value)
|
||||||
value = Regexp.escape(value) if value.is_a? String
|
value = case value
|
||||||
Regexp.new(RELOCATABLE_PATH_REGEX_PREFIX.source + Regexp.escape(value))
|
when String
|
||||||
|
Regexp.escape(value)
|
||||||
|
when Regexp
|
||||||
|
value.source
|
||||||
|
end
|
||||||
|
Regexp.new(RELOCATABLE_PATH_REGEX_PREFIX.source + value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user