diff --git a/lib/cask/source/path_base.rb b/lib/cask/source/path_base.rb index e96f01bdda2c..59265922b26d 100644 --- a/lib/cask/source/path_base.rb +++ b/lib/cask/source/path_base.rb @@ -45,12 +45,17 @@ def load # munge text cask_string.sub!(%r{\A(\s*\#[^\n]*\n)+}, ''); if %r{\A\s*cask\s+:v([\d_]+)(test)?\s+=>\s+([\'\"])(\S+?)\3(?:\s*,\s*|\s+)do\s*\n}.match(cask_string) - dsl_version = $1 + dsl_version_string = $1 test_cask = ! $2.nil? header_name = $4 + dsl_version = Gem::Version.new(dsl_version_string.gsub('_','.')) superclass_name = test_cask ? 'TestCask' : 'Cask' cask_string.sub!(%r{\A[^\n]+\n}, "class #{cask_class_name} < #{superclass_name}\n") - # todo enforce valid DSL version + # todo the minimum DSL version should be defined globally elsewhere + minimum_dsl_version = Gem::Version.new('1.0') + unless dsl_version >= minimum_dsl_version + raise CaskInvalidError.new(cask_name, "Bad header line: 'v#{dsl_version_string}' is less than required minimum version '#{minimum_dsl_version}'") + end if header_name != cask_name raise CaskInvalidError.new(cask_name, "Bad header line: '#{header_name}' does not match file name") end diff --git a/test/cask/dsl_test.rb b/test/cask/dsl_test.rb index 149324a7cab6..12fcb133429b 100644 --- a/test/cask/dsl_test.rb +++ b/test/cask/dsl_test.rb @@ -32,6 +32,16 @@ end end + describe "header line" do + it "requires a valid minimum DSL version in the header" do + err = lambda { + invalid_cask = Cask.load('invalid/invalid-header-version') + }.must_raise(CaskInvalidError) + err.message.must_include 'Bad header line' + err.message.must_include 'is less than required minimum version' + end + end + describe "sha256 stanza" do it "lets you set checksum via sha256" do ChecksumCask = Class.new(Cask) diff --git a/test/support/Casks/invalid/invalid-header-version.rb b/test/support/Casks/invalid/invalid-header-version.rb new file mode 100644 index 000000000000..55392287856b --- /dev/null +++ b/test/support/Casks/invalid/invalid-header-version.rb @@ -0,0 +1,9 @@ +cask :v0_9test => 'invalid-header-version' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end