-
Notifications
You must be signed in to change notification settings - Fork 22.2k
Return hash with_indifferent_access on Session::JsonSerializer #13910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for changing to JSON.load? We can't use that for security reasons. If you encountered any problems with JSON.parse here, we find out what those are and fix those problems.
|
@chancancode sorry I was doing some testing and forgot to use |
|
oops replied to that one here #13910 (comment) |
|
@huoxito a test-case for this in the test suite would be nice :) |
|
I am testing this case and actually getting same results with both |
|
@huoxito you won't be able to test |
|
yeah @lukesarnacki thanks I was trying to modify this test here https://github.com/rails/rails/blob/9b2a017aa82f95911280ed597e4bf3193c9399e9/actionpack/test/dispatch/cookies_test.rb#L398-407 to create a new |
We need to be able to access data, flash messages example, as both flash[:success] and flash["success"]
|
@guilleiguaran just added a test case \o/ please let me know if that doesn't make sense 🍻 |
|
Thanks for your work on this @huoxito :). I am wondering about design of this solution though. Main difference between Marshal and JSON is that generating latter doesn't persist data types. So consider such code: h = { hodor: "HODOR"}.with_indifferent_access
JSON.parse(JSON.generate(h, quirks_mode: true), quirks_mode: true).class
# => Hash
Marshal.load(Marshal.dump(h)).class
# => ActiveSupport::HashWithIndifferentAccess
Since session should be simple, maybe json as default is not a problem (if at least HWIA behaviour would be there), but maybe it would be good to rethink this a little bit. EDIT: Same test using |
|
interesting @lukesarnacki thanks for pointing that out I hadn't realized it. Either way I suppose this is just a matter of where should we call |
|
I would like to hear more opinions about this before of take a decision. |
|
Update: there are some additional work to be done for the serialization, we are tacking those in #13945, this will probably be fixed as part of that work |
We need to be able to access data, flash messages example, as both
flash[:success] and flash["success"].
Hey guys I've been trying to write a regression test for this to prove my point but couldn't so far. I'm doing something like this in dispatch/cookies_test.rb
I've been running spree build on rails edge and realized a bunch of tests failing were related to missing flash message content on the view. It took me a while to see that rails generate a session_store with
serializer: :jsonand successfully reproduce that on a spree app itself.This is related to b23ffd0 and fd48786. Let me know if doesn't make any sense. I can't access
flash[:success]on views unless I add that call in JsonSerializer.// @lukesarnacki @guilleiguaran was this working properly for you guys?