From 181adae94bf4e5e7e726e4efc7aaddc8ca0ab7d4 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sat, 22 Aug 2009 17:26:15 +0100 Subject: Proper validation of Formula.name and version --- Library/Homebrew/formula.rb | 18 +++++++++++++----- Library/Homebrew/unittest.rb | 6 +++--- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index ff4516777..5eeadddf0 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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 diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb index 3bc0b6f61..c4d2a118d 100755 --- a/Library/Homebrew/unittest.rb +++ b/Library/Homebrew/unittest.rb @@ -281,10 +281,10 @@ class BeerTasting