diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index a70285ec56..7964497a79 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -483,7 +483,13 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy if (filename_with_encoding = content_disposition.parameters["filename*"]) encoding, encoded_filename = filename_with_encoding.split("''", 2) - filename = URI.decode_www_form_component(encoded_filename).encode(encoding) if encoding && encoded_filename + # If the `filename*` has incorrectly added double quotes, e.g. + # content-disposition: attachment; filename="myapp-1.2.3.pkg"; filename*=UTF-8''"myapp-1.2.3.pkg" + # Then the encoded_filename will come back as the empty string, in which case we should fall back to the + # `filename` parameter. + if encoding && encoded_filename.present? + filename = URI.decode_www_form_component(encoded_filename).encode(encoding) + end end # Servers may include '/' in their Content-Disposition filename header. Take only the basename of this, because: