Proper validation of Formula.name and version
This commit is contained in:
parent
c53e10f4aa
commit
b6ccdad53e
@ -32,14 +32,14 @@ end
|
||||
# Derive and define at least @url, see Library/Formula for examples
|
||||
class Formula
|
||||
# Homebrew determines the name
|
||||
def initialize name=nil
|
||||
def initialize name='__UNKNOWN__'
|
||||
@url=self.class.url unless @url
|
||||
raise if @url.nil?
|
||||
@name=name
|
||||
raise if @name =~ /\s/
|
||||
validate_variable :name
|
||||
@version=self.class.version unless @version
|
||||
@version=Pathname.new(@url).version unless @version
|
||||
raise if @version =~ /\s/
|
||||
validate_variable :version if @version
|
||||
@homepage=self.class.homepage unless @homepage
|
||||
@md5=self.class.md5 unless @md5
|
||||
@sha1=self.class.sha1 unless @sha1
|
||||
@ -53,8 +53,8 @@ class Formula
|
||||
end
|
||||
|
||||
def prefix
|
||||
raise "Invalid @name" if @name.nil? or @name.empty?
|
||||
raise "Invalid @version" if @version.nil? or @version.empty?
|
||||
validate_variable :name
|
||||
validate_variable :version
|
||||
HOMEBREW_CELLAR+@name+@version
|
||||
end
|
||||
|
||||
@ -100,6 +100,9 @@ class Formula
|
||||
|
||||
# yields self with current working directory set to the uncompressed tarball
|
||||
def brew
|
||||
validate_variable :name
|
||||
validate_variable :version
|
||||
|
||||
stage do
|
||||
begin
|
||||
patch
|
||||
@ -238,6 +241,11 @@ private
|
||||
end
|
||||
end
|
||||
|
||||
def validate_variable name
|
||||
v=eval("@#{name}")
|
||||
raise "Invalid @#{name}" if v.nil? or v.empty? or v =~ /\s/
|
||||
end
|
||||
|
||||
def method_added method
|
||||
raise 'You cannot override Formula.brew' if method == 'brew'
|
||||
end
|
||||
|
||||
@ -281,10 +281,10 @@ class BeerTasting <Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_abstract_formula
|
||||
f=MostlyAbstractFormula.new ''
|
||||
assert_equal '', f.name
|
||||
f=MostlyAbstractFormula.new
|
||||
assert_equal '__UNKNOWN__', f.name
|
||||
assert_raises(RuntimeError) { f.prefix }
|
||||
nostdout { assert_raises(ExecutionError) { f.brew } }
|
||||
nostdout { assert_raises(RuntimeError) { f.brew } }
|
||||
end
|
||||
|
||||
def test_zip
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user