mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
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.
This commit is contained in:
parent
f06b54f1bb
commit
06f2b50ee4
@ -303,7 +303,11 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
|
|||||||
# We can't use basename_without_params, because given a URL like
|
# We can't use basename_without_params, because given a URL like
|
||||||
# https://example.com/download.php?file=foo-1.0.tar.gz
|
# https://example.com/download.php?file=foo-1.0.tar.gz
|
||||||
# the extension we want is ".tar.gz", not ".php".
|
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -209,6 +209,19 @@ describe CurlDownloadStrategy do
|
|||||||
it "parses the opts and sets the corresponding args" do
|
it "parses the opts and sets the corresponding args" do
|
||||||
expect(subject.send(:_curl_opts)).to eq(["--user", "download:123456"])
|
expect(subject.send(:_curl_opts)).to eq(["--user", "download:123456"])
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe DownloadStrategyDetector do
|
describe DownloadStrategyDetector do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user