aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorKevin Abel2018-01-09 19:56:54 -0600
committerKevin Abel2018-01-09 19:56:54 -0600
commit06f2b50ee4b1b5db6737c4dc670536ca97cc7bb4 (patch)
treebd8630badc51e50d2763adce3ef1978409e70e6f /Library
parentf06b54f1bb7dffb319ec7407e309e260ce651517 (diff)
downloadbrew-06f2b50ee4b1b5db6737c4dc670536ca97cc7bb4.tar.bz2
Fix cached download file extension for certain URL
PHP URLs have the downloadable file in the middle of the pathname. If no extension is detected, continue up the pathname.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/download_strategy.rb6
-rw-r--r--Library/Homebrew/test/download_strategies_spec.rb13
2 files changed, 18 insertions, 1 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index feb518057..6869d3370 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -303,7 +303,11 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
# We can't use basename_without_params, because given a URL like
# https://example.com/download.php?file=foo-1.0.tar.gz
# the extension we want is ".tar.gz", not ".php".
- Pathname.new(@url).extname[/[^?]+/]
+ url_pathname = Pathname.new(@url)
+ while !ext = url_pathname.extname[/[^?]+/]
+ url_pathname = url_pathname.dirname
+ end
+ ext
end
end
diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb
index 06d6fa855..7ad070fc4 100644
--- a/Library/Homebrew/test/download_strategies_spec.rb
+++ b/Library/Homebrew/test/download_strategies_spec.rb
@@ -209,6 +209,19 @@ describe CurlDownloadStrategy do
it "parses the opts and sets the corresponding args" do
expect(subject.send(:_curl_opts)).to eq(["--user", "download:123456"])
end
+
+ describe "#tarball_path" do
+ subject { described_class.new(name, resource).tarball_path }
+
+ context "when URL ends with file" do
+ it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") }
+ end
+
+ context "when URL file is in middle" do
+ let(:url) { "http://example.com/foo.tar.gz/from/this/mirror" }
+ it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") }
+ end
+ end
end
describe DownloadStrategyDetector do