diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 1f3a7be4787..195c8142357 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -29,7 +29,7 @@ class UploadsController < ApplicationController return render_404 unless Discourse.store.internal? return render_404 if SiteSetting.prevent_anons_from_downloading_files && current_user.nil? - if upload = Upload.find_by(sha1: params[:sha]) || Upload.find_by(id: params[:id], url: request.fullpath) + if upload = Upload.find_by(sha1: params[:sha]) || Upload.find_by(id: params[:id], url: request.env["PATH_INFO"]) opts = { filename: upload.original_filename } opts[:disposition] = 'inline' if params[:inline] send_file(Discourse.store.path_for(upload), opts) diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index 0cd03ea570f..cf777cfd2e2 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -133,7 +133,7 @@ describe UploadsController do end it "returns 404 when the upload doens't exist" do - Upload.expects(:find_by).with(sha1: sha).returns(nil) + Upload.stubs(:find_by).returns(nil) get :show, site: site, sha: sha, extension: "pdf" expect(response.response_code).to eq(404)