Project

General

Profile

Defect #42839 » 42839.patch

Go MAEDA, 2025-06-28 10:09

View differences:

app/controllers/repositories_controller.rb
160 160
      # Force the download
161 161
      send_opt = {:filename => filename_for_content_disposition(@path.split('/').last)}
162 162
      send_type = Redmine::MimeType.of(@path)
163
      send_opt[:type] = send_type.to_s if send_type
163
      case send_type
164
      when nil
165
        # No MIME type detected. Let Rails use the default type.
166
      when 'application/javascript'
167
        # Avoid ActionController::InvalidCrossOriginRequest exception by forcing download
168
        send_opt[:type] = 'application/octet-stream'
169
      else
170
        send_opt[:type] = send_type
171
      end
164 172
      send_opt[:disposition] = disposition(@path)
165 173
      send_data @repository.cat(@path, @rev), send_opt
166 174
    else
test/functional/repositories_subversion_controller_test.rb
358 358
      assert_equal "attachment; filename=\"helloworld.c\"; filename*=UTF-8''helloworld.c", @response.headers['Content-Disposition']
359 359
    end
360 360

  
361
    def test_entry_download_should_force_download_for_js_files
362
      # JavaScript files should be served as 'application/octet-stream'
363
      # to avoid ActionController::InvalidCrossOriginRequest exception
364
      assert_equal 0, @repository.changesets.count
365
      @repository.fetch_changesets
366
      @project.reload
367
      assert_equal NUM_REV, @repository.changesets.count
368
      get(
369
        :raw,
370
        :params => {
371
          :id => PRJ_ID,
372
          :repository_id => @repository.id,
373
          :path => repository_path_hash(['subversion_test', 'foo.js'])[:param]
374
        }
375
      )
376
      assert_response :success
377
      assert_equal 'application/octet-stream', @response.media_type
378
      assert_match /attachment/, @response.headers['Content-Disposition']
379
    end
380

  
361 381
    def test_directory_entry
362 382
      assert_equal 0, @repository.changesets.count
363 383
      @repository.fetch_changesets
(2-2/3)