From 267040e5df2ea6981d07e4f1d39a26a4c46eee5c Mon Sep 17 00:00:00 2001 From: Cassidy Marble Date: Fri, 12 Mar 2021 10:26:59 -0700 Subject: [PATCH] bugfix: Add args and options to lazy url block --- Library/Homebrew/cask/dsl.rb | 6 ++++- Library/Homebrew/test/cask/audit_spec.rb | 30 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 244ebf38f4..a46a7c18bc 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -181,7 +181,11 @@ module Cask set_unique_stanza(:url, args.empty? && options.empty? && !block_given?) do if block_given? - LazyObject.new { URL.new(*yield, from_block: true, caller_location: caller_location) } + LazyObject.new do + *args = yield + options = args.last.is_a?(Hash) ? args.pop : {} + URL.new(*args, **options, from_block: true, caller_location: caller_location) + end else URL.new(*args, **options, caller_location: caller_location) end diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index f94b52f526..23d0009db9 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -981,5 +981,35 @@ describe Cask::Audit, :cask do it { is_expected.to fail_with(/a homepage stanza is required/) } end + + context "when url is lazy" do + let(:strict) { true } + let(:cask_token) { "with-lazy" } + let(:cask) do + tmp_cask cask_token.to_s, <<~RUBY + cask '#{cask_token}' do + version '1.8.0_72,8.13.0.5' + sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a' + url do + ['https://brew.sh/foo.zip', {referer: 'https://example.com', cookies: {'foo' => 'bar'}}] + end + name 'Audit' + desc 'Audit Description' + homepage 'https://brew.sh' + app 'Audit.app' + end + RUBY + end + + it { is_expected.to pass } + + it "receives a referer" do + expect(audit.cask.url.referer).to eq "https://example.com" + end + + it "receives cookies" do + expect(audit.cask.url.cookies).to eq "foo" => "bar" + end + end end end