mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
download_strategy: handle incorrectly quoted filename* headers
Some servers erroneously double-quote the filename in the filename* header. This is (as far as I can tell from the spec) a bug in the server, and should be fixed there. In general though using `""` as the filename seems like behaviour worth handling in brew anyway, as there may be other places where the parser returns an empty string. Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
3e2c713c92
commit
160e7da779
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user