mirror of
https://github.com/discourse/discourse.git
synced 2025-03-04 14:54:11 +08:00
FIX: displaying wrong avatar and letter avatar
correct regression where params and env is reused in production
This commit is contained in:
parent
5a715b7d55
commit
ca7af7b88f
@ -7,11 +7,26 @@ module Hijack
|
|||||||
|
|
||||||
def hijack(&blk)
|
def hijack(&blk)
|
||||||
controller_class = self.class
|
controller_class = self.class
|
||||||
request = self.request
|
|
||||||
|
#env = request.env.dup
|
||||||
|
#request_copy = ActionDispatch::Request.new(env)
|
||||||
|
request_copy = self.request
|
||||||
|
|
||||||
if hijack = request.env['rack.hijack']
|
if hijack = request.env['rack.hijack']
|
||||||
io = hijack.call
|
io = hijack.call
|
||||||
|
|
||||||
|
# in prd the env object is re-used
|
||||||
|
# make a copy of all strings
|
||||||
|
env_copy = {}
|
||||||
|
request.env.each do |k, v|
|
||||||
|
env_copy[k] = v if String === v
|
||||||
|
end
|
||||||
|
|
||||||
|
request_copy = ActionDispatch::Request.new(env_copy)
|
||||||
|
|
||||||
|
# params is generated per request so we can simply reuse it
|
||||||
|
params_copy = params
|
||||||
|
|
||||||
Scheduler::Defer.later("hijack work") do
|
Scheduler::Defer.later("hijack work") do
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -24,7 +39,8 @@ module Hijack
|
|||||||
instance = controller_class.new
|
instance = controller_class.new
|
||||||
response = ActionDispatch::Response.new
|
response = ActionDispatch::Response.new
|
||||||
instance.response = response
|
instance.response = response
|
||||||
instance.request = request
|
instance.request = request_copy
|
||||||
|
instance.params = params_copy
|
||||||
|
|
||||||
begin
|
begin
|
||||||
instance.instance_eval(&blk)
|
instance.instance_eval(&blk)
|
||||||
|
@ -8,8 +8,10 @@ describe Hijack do
|
|||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@io = StringIO.new
|
@io = StringIO.new
|
||||||
self.request = ActionController::TestRequest.new(
|
self.request = ActionController::TestRequest.new({
|
||||||
{ "rack.hijack" => lambda { @io } },
|
"rack.hijack" => lambda { @io },
|
||||||
|
"rack.input" => StringIO.new
|
||||||
|
},
|
||||||
nil,
|
nil,
|
||||||
nil
|
nil
|
||||||
)
|
)
|
||||||
@ -27,6 +29,18 @@ describe Hijack do
|
|||||||
Hijack::Tester.new
|
Hijack::Tester.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "dupes the request params and env" do
|
||||||
|
orig_req = tester.request
|
||||||
|
copy_req = nil
|
||||||
|
|
||||||
|
tester.hijack_test do
|
||||||
|
copy_req = request
|
||||||
|
render body: "hello world", status: 200
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(copy_req.object_id).not_to eq(orig_req.object_id)
|
||||||
|
end
|
||||||
|
|
||||||
it "handles expires_in" do
|
it "handles expires_in" do
|
||||||
tester.hijack_test do
|
tester.hijack_test do
|
||||||
expires_in 1.year
|
expires_in 1.year
|
||||||
|
Loading…
x
Reference in New Issue
Block a user