Project

General

Profile

Feature #29914 » 0013-Remove-filename_for_content_disposition-for-MS-brows.patch

Marius BĂLTEANU, 2021-03-30 18:42

View differences:

app/controllers/application_controller.rb
692 692

  
693 693
  # Returns a string that can be used as filename value in Content-Disposition header
694 694
  def filename_for_content_disposition(name)
695
    %r{(MSIE|Trident|Edge)}.match?(request.env['HTTP_USER_AGENT'].to_s) ? ERB::Util.url_encode(name) : name
695
    name
696 696
  end
697 697

  
698 698
  def api_request?
test/functional/wiki_controller_test.rb
1152 1152
    assert_include 'h1. CookBook documentation v2', @response.body
1153 1153
  end
1154 1154

  
1155
  def test_show_filename_should_be_uri_encoded_for_ms_browsers
1155
  def test_show_filename_should_be_uri_encoded
1156 1156
    @request.session[:user_id] = 2
1157 1157
    title = 'Этика_менеджмента'
1158 1158
    %w|pdf html txt|.each do |format|
......
1160 1160
      @request.user_agent = ""
1161 1161
      get :show, :params => {:project_id => 1, :id => title, :format => format}
1162 1162
      assert_response :success
1163
      assert_equal "attachment; filename=\"#{title}.#{format}\"",
1163
      ascii_filename = "%3F%3F%3F%3F%3F_%3F%3F%3F%3F%3F%3F%3F%3F%3F%3F%3F.#{format}"
1164
      utf8_filename = "%D0%AD%D1%82%D0%B8%D0%BA%D0%B0_%D0%BC%D0%B5%D0%BD%D0%B5%D0%B4%D0%B6%D0%BC%D0%B5%D0%BD%D1%82%D0%B0.#{format}"
1165
      assert_equal "attachment; filename=\"#{ascii_filename}\"; filename*=UTF-8''#{utf8_filename}",
1164 1166
                   @response.headers['Content-Disposition']
1165
      # Microsoft's browsers: filename should be URI encoded
1167
      # Microsoft's browsers
1166 1168
      @request.user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063'
1167 1169
      get :show, :params => {:project_id => 1, :id => title, :format => format}
1168 1170
      assert_response :success
1169
      filename = Addressable::URI.encode("#{title}.#{format}")
1170
      assert_equal "attachment; filename=\"#{filename}\"",
1171
      assert_equal "attachment; filename=\"#{ascii_filename}\"; filename*=UTF-8''#{utf8_filename}",
1171 1172
                   @response.headers['Content-Disposition']
1172 1173
    end
1173 1174
  end
(18-18/21)