Escape paths in regexps

This commit is contained in:
Jack Nagel 2014-07-06 11:24:24 -05:00
parent 7e268670ed
commit f8fb74ff76
3 changed files with 3 additions and 3 deletions

View File

@ -123,7 +123,7 @@ module Homebrew
case path.to_s case path.to_s
when HOMEBREW_TAP_PATH_REGEX when HOMEBREW_TAP_PATH_REGEX
"#$1/#$2/#{File.basename($3, '.rb')}" "#$1/#$2/#{File.basename($3, '.rb')}"
when %r{^#{HOMEBREW_LIBRARY}/Formula/(.+)} when %r{^#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Formula/(.+)}o
"Homebrew/homebrew/#{File.basename($1, '.rb')}" "Homebrew/homebrew/#{File.basename($1, '.rb')}"
else else
nil nil

View File

@ -266,7 +266,7 @@ class Report
def select_formula key def select_formula key
fetch(key, []).map do |path| fetch(key, []).map do |path|
case path.to_s case path.to_s
when Regexp.new(HOMEBREW_LIBRARY + "/Formula") when %r{^#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Formula}o
path.basename(".rb").to_s path.basename(".rb").to_s
when HOMEBREW_TAP_PATH_REGEX when HOMEBREW_TAP_PATH_REGEX
"#$1/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}" "#$1/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}"

View File

@ -3,6 +3,6 @@ HOMEBREW_TAP_ARGS_REGEX = %r{^([\w-]+)/(homebrew-)?([\w-]+)$}
# match taps' formula, e.g. someuser/sometap/someformula # match taps' formula, e.g. someuser/sometap/someformula
HOMEBREW_TAP_FORMULA_REGEX = %r{^([\w-]+)/([\w-]+)/([\w+-]+)$} HOMEBREW_TAP_FORMULA_REGEX = %r{^([\w-]+)/([\w-]+)/([\w+-]+)$}
# match taps' directory path, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap # match taps' directory path, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap
HOMEBREW_TAP_DIR_REGEX = %r{#{HOMEBREW_LIBRARY}/Taps/([\w-]+)/([\w-]+)} HOMEBREW_TAP_DIR_REGEX = %r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/([\w-]+)/([\w-]+)}
# match taps' formula path, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula # match taps' formula path, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula
HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{/(.*)}.source) HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{/(.*)}.source)