Skip to content

Commit

Permalink
fix the Flash middleware loading the session on every request (very d…
Browse files Browse the repository at this point in the history
…angerous especially with Rack::Cache), it should only be loaded when the flash method is called
  • Loading branch information
willbryant committed Apr 28, 2012
1 parent 9fc9e89 commit 5638adf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion actionpack/lib/action_controller/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ def process(action, http_method = 'GET', *args)

@request.session = ActionController::TestSession.new(session) if session
@request.session["flash"] = @request.flash.update(flash || {})
@request.session["flash"].sweep

@controller.request = @request
build_request_uri(action, parameters)
Expand Down
9 changes: 3 additions & 6 deletions actionpack/lib/action_dispatch/middleware/flash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Request
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
# to put a new one.
def flash
@env[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new)
@env[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new).tap(&:sweep)
end
end

Expand Down Expand Up @@ -217,10 +217,6 @@ def initialize(app)
end

def call(env)
if (session = env['rack.session']) && (flash = session['flash'])
flash.sweep
end

@app.call(env)
ensure
session = env['rack.session'] || {}
Expand All @@ -237,7 +233,8 @@ def call(env)
env[KEY] = new_hash
end

if session.key?('flash') && session['flash'].empty?
if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
session.key?('flash') && session['flash'].empty?
session.delete('flash')
end
end
Expand Down

0 comments on commit 5638adf

Please sign in to comment.