summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2025-07-06 05:00:41 +0000
committerGo MAEDA <maeda@farend.jp>2025-07-06 05:00:41 +0000
commite93a9bc5607edd75ef8fc59e42e2f624a5375231 (patch)
tree5e63988cf2a8bfeb2c4a567707f28d1b8dd87019
parenteedc0001be7d86a52d0eca6ee0995585fff2ce82 (diff)
downloadredmine-e93a9bc5607edd75ef8fc59e42e2f624a5375231.tar.gz
redmine-e93a9bc5607edd75ef8fc59e42e2f624a5375231.zip
Merged r23857 from trunk to 5.1-stable (#42839).
git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@23864 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/repositories_controller.rb10
-rw-r--r--test/functional/repositories_subversion_controller_test.rb21
2 files changed, 30 insertions, 1 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index a5ffb4451..7e129348a 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -156,7 +156,15 @@ class RepositoriesController < ApplicationController
# Force the download
send_opt = {:filename => filename_for_content_disposition(@path.split('/').last)}
send_type = Redmine::MimeType.of(@path)
- send_opt[:type] = send_type.to_s if send_type
+ case send_type
+ when nil
+ # No MIME type detected. Let Rails use the default type.
+ when 'application/javascript'
+ # Avoid ActionController::InvalidCrossOriginRequest exception by setting non-JS content type
+ send_opt[:type] = 'text/plain'
+ else
+ send_opt[:type] = send_type
+ end
send_opt[:disposition] = disposition(@path)
send_data @repository.cat(@path, @rev), send_opt
else
diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb
index 7d7421fd8..44cc0a0b4 100644
--- a/test/functional/repositories_subversion_controller_test.rb
+++ b/test/functional/repositories_subversion_controller_test.rb
@@ -357,6 +357,27 @@ class RepositoriesSubversionControllerTest < Redmine::RepositoryControllerTest
assert_equal "attachment; filename=\"helloworld.c\"; filename*=UTF-8''helloworld.c", @response.headers['Content-Disposition']
end
+ def test_entry_should_return_text_plain_for_js_files
+ # JavaScript files should be served as 'text/plain' instead of
+ # 'application/javascript' to avoid
+ # ActionController::InvalidCrossOriginRequest exception
+ assert_equal 0, @repository.changesets.count
+ @repository.fetch_changesets
+ @project.reload
+ assert_equal NUM_REV, @repository.changesets.count
+ get(
+ :raw,
+ :params => {
+ :id => PRJ_ID,
+ :repository_id => @repository.id,
+ :path => repository_path_hash(['subversion_test', 'foo.js'])[:param]
+ }
+ )
+ assert_response :success
+ assert_equal 'text/plain', @response.media_type
+ assert_match /attachment/, @response.headers['Content-Disposition']
+ end
+
def test_directory_entry
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets