diff options
author | Rémy Coutable <remy@rymai.me> | 2018-06-18 11:56:12 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-06-18 11:56:12 +0300 |
commit | b7700e0963675ce4dde85d4f3fe13e0e047a1950 (patch) | |
tree | 568c68643b3c0b2515cee7fa741091afa73019ea /app/controllers | |
parent | 4be23eeae376ede50905b741f88b089b1669b07f (diff) | |
parent | 037334d2f29fbb14d5e366a7b892a75631eb9ace (diff) |
Merge branch 'blackst0ne-rails5-fix-blob-requests-format' into 'master'
[Rails5] Explicitly set request.format for blob_controller
Closes #47921
See merge request gitlab-org/gitlab-ce!19876
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/blob_controller.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 7c65f1f5dfe..a8c0a68fc17 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -7,6 +7,7 @@ class Projects::BlobController < Projects::ApplicationController prepend_before_action :authenticate_user!, only: [:edit] + before_action :set_request_format, only: [:edit, :show, :update] before_action :require_non_empty_project, except: [:new, :create] before_action :authorize_download_code! @@ -188,6 +189,18 @@ class Projects::BlobController < Projects::ApplicationController .last_for_path(@repository, @ref, @path).sha end + # In Rails 4.2 if params[:format] is empty, Rails set it to :html + # But since Rails 5.0 the framework now looks for an extension. + # E.g. for `blob/master/CHANGELOG.md` in Rails 4 the format would be `:html`, but in Rails 5 on it'd be `:md` + # This before_action explicitly sets the `:html` format for all requests unless `:format` is set by a client e.g. by JS for XHR requests. + def set_request_format + request.format = :html if set_request_format? + end + + def set_request_format? + params[:id].present? && params[:format].blank? && request.format != "json" + end + def show_html environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit } @environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last |