Skip to content
Snippets Groups Projects

Encode Content-Disposition filenames

Merged Stan Hu requested to merge sh-encode-content-disposition into master
All threads resolved!
@@ -57,10 +57,12 @@ def dynamic_segment
let(:params) { { attachment: filename } }
it 'sends a file with content-type of text/plain' do
# Notice the filename= is omitted from the disposition; this is because
# Rails 5 will append this header in send_file
expected_params = {
content_type: 'text/plain',
filename: 'test.js',
disposition: "attachment; filename=\"test.js\"; filename*=UTF-8''test.js"
disposition: "attachment; filename*=UTF-8''test.js"
}
expect(controller).to receive(:send_file).with(uploader.path, expected_params)
@@ -70,10 +72,12 @@ def dynamic_segment
context 'with non-ASCII encoded filename' do
let(:filename) { 'テスト.txt' }
# Notice the filename= is omitted from the disposition; this is because
# Rails 5 will append this header in send_file
it 'sends content-disposition for non-ASCII encoded filenames' do
expected_params = {
filename: filename,
disposition: "attachment; filename=\"%3F%3F%3F.txt\"; filename*=UTF-8''%E3%83%86%E3%82%B9%E3%83%88.txt"
disposition: "attachment; filename*=UTF-8''%E3%83%86%E3%82%B9%E3%83%88.txt"
}
expect(controller).to receive(:send_file).with(uploader.path, expected_params)
Loading