From 890485cfce4c361c03a41ec23b0ba187007818cc Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Sun, 9 Sep 2018 16:35:48 +0900 Subject: Encode Content-Disposition filenames on send_data and send_file --- activestorage/test/models/blob_test.rb | 2 +- .../test/models/filename/parameters_test.rb | 32 ---------------------- 2 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 activestorage/test/models/filename/parameters_test.rb (limited to 'activestorage/test/models') diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb index 88c106a08b..1a6a89de56 100644 --- a/activestorage/test/models/blob_test.rb +++ b/activestorage/test/models/blob_test.rb @@ -185,7 +185,7 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase private def expected_url_for(blob, disposition: :inline, filename: nil) filename ||= blob.filename - query_string = { content_type: blob.content_type, disposition: "#{disposition}; #{filename.parameters}" }.to_param + query_string = { content_type: blob.content_type, disposition: ActionDispatch::Http::ContentDisposition.format(disposition: disposition, filename: filename.sanitized) }.to_param "https://example.com/rails/active_storage/disk/#{ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key)}/#{filename}?#{query_string}" end end diff --git a/activestorage/test/models/filename/parameters_test.rb b/activestorage/test/models/filename/parameters_test.rb deleted file mode 100644 index 431be00639..0000000000 --- a/activestorage/test/models/filename/parameters_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class ActiveStorage::Filename::ParametersTest < ActiveSupport::TestCase - test "parameterizing a Latin filename" do - filename = ActiveStorage::Filename.new("racecar.jpg") - - assert_equal %(filename="racecar.jpg"), filename.parameters.ascii - assert_equal "filename*=UTF-8''racecar.jpg", filename.parameters.utf8 - assert_equal "#{filename.parameters.ascii}; #{filename.parameters.utf8}", filename.parameters.combined - assert_equal filename.parameters.combined, filename.parameters.to_s - end - - test "parameterizing a Latin filename with accented characters" do - filename = ActiveStorage::Filename.new("råcëçâr.jpg") - - assert_equal %(filename="racecar.jpg"), filename.parameters.ascii - assert_equal "filename*=UTF-8''r%C3%A5c%C3%AB%C3%A7%C3%A2r.jpg", filename.parameters.utf8 - assert_equal "#{filename.parameters.ascii}; #{filename.parameters.utf8}", filename.parameters.combined - assert_equal filename.parameters.combined, filename.parameters.to_s - end - - test "parameterizing a non-Latin filename" do - filename = ActiveStorage::Filename.new("автомобиль.jpg") - - assert_equal %(filename="%3F%3F%3F%3F%3F%3F%3F%3F%3F%3F.jpg"), filename.parameters.ascii - assert_equal "filename*=UTF-8''%D0%B0%D0%B2%D1%82%D0%BE%D0%BC%D0%BE%D0%B1%D0%B8%D0%BB%D1%8C.jpg", filename.parameters.utf8 - assert_equal "#{filename.parameters.ascii}; #{filename.parameters.utf8}", filename.parameters.combined - assert_equal filename.parameters.combined, filename.parameters.to_s - end -end -- cgit v1.2.3