Encode Content-Disposition filenames on send_data and send_file#33829
Encode Content-Disposition filenames on send_data and send_file#33829kaspth merged 1 commit intorails:masterfrom
Conversation
georgeclaghorn
left a comment
There was a problem hiding this comment.
Can we remove ActiveStorage::Filename::Parameters?
There was a problem hiding this comment.
Is this :nodoc: comment necessary? What is it excluding from the docs?
5e35120 to
4fb13b9
Compare
|
Thanks, @mtsmfm! A few more things:
|
4fb13b9 to
f6893aa
Compare
|
actionpack/CHANGELOG.md
Outdated
f6893aa to
1d3fa52
Compare
There was a problem hiding this comment.
Don't we need to require this file one? Also action_controller because it is not in Active Storage.
There was a problem hiding this comment.
I think we don't have to require because this file is under app and it's on Rails engine
There was a problem hiding this comment.
Can we avoid [internally] exposing this class entirely? AFAICS, this method's result is only used in:
(And that method seems to have more in common with the surrounding lines in send_file_headers!, too.)
There was a problem hiding this comment.
Can we avoid [internally] exposing this class entirely?
Hmm, how can I avoid?
AFAIK, there's no way to share this logic across gems without exposing class/module
There was a problem hiding this comment.
I think Matthew’s suggesting removing the parameters method here and using the new class directly in ActiveStorage::Service#content_disposition_with.
There was a problem hiding this comment.
I was thinking of something like ActionController::ContentDisposition.format(:inline, filename: "hello.jpg") # => "inline; filename=[...]"
So we still need to expose a constant (and following @rafaelfranca's suggestion to move it out of the DataStreaming namespace), but having it do the work internally, and just return a string. It just feels a bit odd to me that we're exposing the class instance, when all we want to do is call to_s on it.
There was a problem hiding this comment.
If we want to reuse inside Active Storage I don't think it should be inside DataStreaming. ActionController:: DispositionFilename is a better name.
There was a problem hiding this comment.
ah, you also meant DispositionFilenameParameters should be renamed to DispositionFilename, right?
There was a problem hiding this comment.
Right, but maybe DispositionFilenameParameter is better.
ba2d8aa to
60e29b5
Compare
seems failed test isn't related to this PR |
There was a problem hiding this comment.
@rafaelfranca Now I think this class should be put into the same place as ActionDispatch::Http::UploadedFile.
It seems all helper stuff is placed in ActionDispatch.
So I propose to rename this class to ActionDispatch::Http::ContentDisposition.
What do you think?
There was a problem hiding this comment.
Good point. Makes sense to me.
There was a problem hiding this comment.
This require should be probably inside lib/active_storage/service.rb
There was a problem hiding this comment.
Good point. Makes sense to me.
60e29b5 to
890485c
Compare
|
@georgeclaghorn @rafaelfranca @matthewd I fixed all points you reviewed. Can you review again, please? |
|
@georgeclaghorn Can I ask you to review? |
|
Thanks! |
`ActiveStorage::Filename#parameters` was removed by rails#33829.
Users downloading non-ASCII attachments would see garbled characters. When used with object storage, AWS S3 would return an InvalidArgument error: Header value cannot be represented using ISO-8859-1. Per RFC 5987 and RFC 6266, Content-Disposition should be encoded properly. This commit takes the Rails 6 implementation of ActiveSuppport::Http::ContentDisposition (rails/rails#33829) and ports it here. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/47673
Encode Content-Disposition filenames on send_data and send_file rails/rails#33829
Summary
A few years ago, @stanhu tried to support non-ascii encodings for
send_dataandsend_file.#21461
but it's still not merged because it lacks tests and some points to be fixed.
In the PR, @jeremy told us how he encodes and actually it's the same how activestorage encodes file name now
I changed
ActiveStorage::Filename::ParameterstoActionController::DataStreaming::DispositionFilenameParametersto encode insend_dataandsend_fileand share the logic.I tested on Chrome, IE11, Safari and Firefox
Chrome
IE11
Safari
Firefox
Script
Other Information
I'm wondering if we can backport this change to older versions-> I created backport gem https://github.com/mtsmfm/action_dispatch-http-content_disposition