Skip to content

Commit

Permalink
download_strategy: strip query string from basename
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Apr 11, 2022
1 parent 6a291c1 commit 36b9801
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,19 @@ def parse_basename(url)
end

uri_path = URI.decode_www_form_component(uri_path)
query_regex = /[^?&]+/

# We need a Pathname because we've monkeypatched extname to support double
# extensions (e.g. tar.gz).
# Given a URL like https://example.com/download.php?file=foo-1.0.tar.gz
# the basename we want is "foo-1.0.tar.gz", not "download.php".
Pathname.new(uri_path).ascend do |path|
ext = path.extname[/[^?&]+/]
return path.basename.to_s[/[^?&]+#{Regexp.escape(ext)}/] if ext
ext = path.extname[query_regex]
return path.basename.to_s[/#{query_regex.source}#{Regexp.escape(ext)}/] if ext
end

File.basename(uri_path)
# Strip query string
File.basename(uri_path)[query_regex]
end
end

Expand Down

0 comments on commit 36b9801

Please sign in to comment.