Merge pull request #14829 from gibfahn/incorrect_headers
download_strategy: handle incorrectly quoted filename* headers
This commit is contained in:
commit
b6b30667f0
@ -483,7 +483,13 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
|
|
||||||
if (filename_with_encoding = content_disposition.parameters["filename*"])
|
if (filename_with_encoding = content_disposition.parameters["filename*"])
|
||||||
encoding, encoded_filename = filename_with_encoding.split("''", 2)
|
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.present? && encoded_filename.present?
|
||||||
|
filename = URI.decode_www_form_component(encoded_filename).encode(encoding)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Servers may include '/' in their Content-Disposition filename header. Take only the basename of this, because:
|
# 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