aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/flash.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2011-04-04 21:52:37 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2011-04-05 10:41:34 -0300
commitd7a5638dfbe68d0a92958c0e81f44054ddd7d291 (patch)
treeccb7b61eda2edd448f7cb648716dcb757f8a10be /actionpack/lib/action_dispatch/middleware/flash.rb
parenta9b4b5da7c216e4464eeb9dbd0a39ea258d64325 (diff)
downloadrails-d7a5638dfbe68d0a92958c0e81f44054ddd7d291.tar.gz
rails-d7a5638dfbe68d0a92958c0e81f44054ddd7d291.tar.bz2
rails-d7a5638dfbe68d0a92958c0e81f44054ddd7d291.zip
raise if someone tries to modify the flash when it was already streamed back to the client or converted to HTTP headers
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/flash.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/flash.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb
index 21aeeb217a..410d3f7127 100644
--- a/actionpack/lib/action_dispatch/middleware/flash.rb
+++ b/actionpack/lib/action_dispatch/middleware/flash.rb
@@ -43,9 +43,15 @@ module ActionDispatch
class FlashNow #:nodoc:
def initialize(flash)
@flash = flash
+ @closed = false
end
+ attr_reader :closed
+ alias :closed? :closed
+ def close!; @closed = true end
+
def []=(k, v)
+ raise ClosedError, "Cannot modify flash because it was closed. This means it was already streamed back to the client or converted to HTTP headers." if closed?
@flash[k] = v
@flash.discard(k)
v
@@ -70,9 +76,15 @@ module ActionDispatch
def initialize #:nodoc:
super
@used = Set.new
+ @closed = false
end
+ attr_reader :closed
+ alias :closed? :closed
+ def close!; @closed = true end
+
def []=(k, v) #:nodoc:
+ raise ClosedError, "Cannot modify flash because it was closed. This means it was already streamed back to the client or converted to HTTP headers." if closed?
keep(k)
super
end
@@ -184,8 +196,11 @@ module ActionDispatch
session = env['rack.session'] || {}
flash_hash = env['action_dispatch.request.flash_hash']
- if flash_hash && (!flash_hash.empty? || session.key?('flash'))
+ if flash_hash
+ if !flash_hash.empty? || session.key?('flash')
session["flash"] = flash_hash
+ end
+ flash_hash.close!
end
if session.key?('flash') && session['flash'].empty?
@@ -193,4 +208,7 @@ module ActionDispatch
end
end
end
+
+ class ClosedError < StandardError #:nodoc:
+ end
end