Skip to content
Permalink
Browse files

Stringify the incoming hash in FlashHash

Stringify the incoming as well to handle incoming symbol keys from
marshalled sessions
  • Loading branch information
guilleiguaran authored and chancancode committed Feb 11, 2014
1 parent a6ce984 commit a668beffd64106a1e1fedb71cc25eaaa11baf0c1
Showing with 3 additions and 1 deletion.
  1. +3 −1 actionpack/lib/action_dispatch/middleware/flash.rb
@@ -1,3 +1,5 @@
require 'active_support/core_ext/hash/keys'

module ActionDispatch
class Request < Rack::Request
# Access the contents of the flash. Use <tt>flash["notice"]</tt> to
@@ -94,7 +96,7 @@ def to_session_value

def initialize(flashes = {}, discard = []) #:nodoc:
@discard = Set.new(stringify_array(discard))
@flashes = flashes
@flashes = flashes.stringify_keys
@now = nil
end

11 comments on commit a668bef

@senny

This comment has been minimized.

Copy link
Member

@senny senny replied Mar 4, 2014

Just upgraded my app to the RC and noticed that Symbol keys changed to String keys. Is this expected behavior? It should be documented in the upgrading guide at least. This will break apps for sure.

@kuldeepaggarwal

This comment has been minimized.

Copy link
Contributor

@kuldeepaggarwal kuldeepaggarwal replied Mar 5, 2014

@senny This won't break any app, as if we try to access notice like flash[:notice], then

def [](k)
  @flash[k.to_s]
end

will save you... 😄

@guilleiguaran

This comment has been minimized.

Copy link
Member Author

@guilleiguaran guilleiguaran replied Mar 5, 2014

@kuldeepaggarwal it breaks apps that were iterating over the keys and checking for specific keys, for example:

<% flash.keys.each do |key, value| %>
    <span class="<%= (key == :notice) ? 'green' : 'red' %>"><%= value %></span>
<% end %>  
@senny

This comment has been minimized.

Copy link
Member

@senny senny replied Mar 5, 2014

@kuldeepaggarwal flash access works but the keys need to be stored in some sort. Before they were symbols and now they are Strings. If you have applications that work with the internal flash representation (like the example of @guilleiguaran) you get different behavior than on Rails 4. I know there are many tutorials and even gems out there that suggest looping through the flash. So this is a compatibility issue.

It's easy to fix though so we need to make sure the user knows what the cause is an how to proceed.

@kuldeepaggarwal

This comment has been minimized.

Copy link
Contributor

@kuldeepaggarwal kuldeepaggarwal replied Mar 5, 2014

Sorry I missed that...

@kuldeepaggarwal

This comment has been minimized.

Copy link
Contributor

@kuldeepaggarwal kuldeepaggarwal replied Mar 9, 2014

@senny So should we update the guide?

@chancancode

This comment has been minimized.

Copy link
Member

@chancancode chancancode replied Mar 9, 2014

@chancancode

This comment has been minimized.

Copy link
Member

@chancancode chancancode replied Mar 9, 2014

@senny

This comment has been minimized.

Copy link
Member

@senny senny replied Mar 9, 2014

i updated the upgrading guide. will take care of changelog/ release guide sync next week.

@kuldeepaggarwal

This comment has been minimized.

Copy link
Contributor

@kuldeepaggarwal kuldeepaggarwal replied Mar 9, 2014

@senny 👍

@chancancode

This comment has been minimized.

Copy link
Member

@chancancode chancancode replied Mar 9, 2014

Please sign in to comment.
You can’t perform that action at this time.