From 06f2b50ee4b1b5db6737c4dc670536ca97cc7bb4 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Tue, 9 Jan 2018 19:56:54 -0600 Subject: 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. --- Library/Homebrew/download_strategy.rb | 6 +++++- Library/Homebrew/test/download_strategies_spec.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew') 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 -- cgit v1.2.3 From dca8dc5bf50c508eadf051d4316cec12dacf7674 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Tue, 9 Jan 2018 20:11:52 -0600 Subject: Fix audit --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 6869d3370..341947544 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -304,7 +304,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy # https://example.com/download.php?file=foo-1.0.tar.gz # the extension we want is ".tar.gz", not ".php". url_pathname = Pathname.new(@url) - while !ext = url_pathname.extname[/[^?]+/] + until ext = url_pathname.extname[/[^?]+/] url_pathname = url_pathname.dirname end ext -- cgit v1.2.3 From 0254605cd52b1bb92ffe33114c671cc111c5a687 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Sat, 13 Jan 2018 17:06:21 -0600 Subject: Handle reaching the top of a URL which searching for file ext Should never reach this as most URL's will have a domain name that will be caught as an extname. --- Library/Homebrew/download_strategy.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 341947544..2774f2fad 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -306,6 +306,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy url_pathname = Pathname.new(@url) until ext = url_pathname.extname[/[^?]+/] url_pathname = url_pathname.dirname + return if url_pathname.to_s == "." end ext end -- cgit v1.2.3 From 601af55b43bc96627359eca06eeec4bf9881c890 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Fri, 2 Feb 2018 18:15:05 -0600 Subject: Add root dirname as a escape value too --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 2774f2fad..ed316fa7f 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -306,7 +306,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy url_pathname = Pathname.new(@url) until ext = url_pathname.extname[/[^?]+/] url_pathname = url_pathname.dirname - return if url_pathname.to_s == "." + return if url_pathname.to_s == "." || url_pathname.to_s == "/" end ext end -- cgit v1.2.3 From ca3fccaf2b4bfe5c4d96a17ac5559f3721d00230 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Mon, 12 Feb 2018 14:22:10 -0600 Subject: Make ext use bounded iterator --- Library/Homebrew/download_strategy.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index ed316fa7f..e85661d76 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -303,12 +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". - url_pathname = Pathname.new(@url) - until ext = url_pathname.extname[/[^?]+/] - url_pathname = url_pathname.dirname - return if url_pathname.to_s == "." || url_pathname.to_s == "/" + Pathname.new(@url).ascend do |path| + ext = path.extname[/[^?]+/] + return ext if ext end - ext + nil end end -- cgit v1.2.3