Make ext use bounded iterator

This commit is contained in:
Kevin Abel 2018-02-12 14:22:10 -06:00
parent 601af55b43
commit ca3fccaf2b
No known key found for this signature in database
GPG Key ID: E0F7636DDDB96BF6

View File

@ -303,12 +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".
url_pathname = Pathname.new(@url) Pathname.new(@url).ascend do |path|
until ext = url_pathname.extname[/[^?]+/] ext = path.extname[/[^?]+/]
url_pathname = url_pathname.dirname return ext if ext
return if url_pathname.to_s == "." || url_pathname.to_s == "/"
end end
ext nil
end end
end end