diff options
| author | Mike McQuaid | 2018-02-13 09:09:11 +0000 | 
|---|---|---|
| committer | GitHub | 2018-02-13 09:09:11 +0000 | 
| commit | 2a9660fb2bd74b41d59b1ecde516531dbb6fd28a (patch) | |
| tree | 6b032afda527e1eab72284d2bbab2eb7dca28bc5 | |
| parent | b3f0e571f4cdcc29dd6982b863fdcd7de5e6febf (diff) | |
| parent | ca3fccaf2b4bfe5c4d96a17ac5559f3721d00230 (diff) | |
| download | brew-2a9660fb2bd74b41d59b1ecde516531dbb6fd28a.tar.bz2 | |
Merge pull request #3657 from kabel/php-cache-ext
Fix cached download file extension for certain URLs
| -rw-r--r-- | Library/Homebrew/download_strategy.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/test/download_strategies_spec.rb | 13 | 
2 files changed, 18 insertions, 1 deletions
| diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index feb518057..e85661d76 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[/[^?]+/] +    Pathname.new(@url).ascend do |path| +      ext = path.extname[/[^?]+/] +      return ext if ext +    end +    nil    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 | 
