aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/cookies.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-08-17 12:40:24 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-08-17 12:41:42 -0700
commite158ee50e64e2ae2460cd26be53039922f588300 (patch)
tree9e0e90d3108c854d8989c5a78ca7c0ae53125c72 /actionpack/lib/action_dispatch/middleware/cookies.rb
parent393e19e508a08ede0f5037bccb984e3eb252d579 (diff)
downloadrails-e158ee50e64e2ae2460cd26be53039922f588300.tar.gz
rails-e158ee50e64e2ae2460cd26be53039922f588300.tar.bz2
rails-e158ee50e64e2ae2460cd26be53039922f588300.zip
Use AS::JSON for (de)serializing cookies
Use the Active Support JSON encoder for cookie jars using the `:json` or `:hybrid` serializer. This allows you to serialize custom Ruby objects into cookies by defining the `#as_json` hook on such objects. Fixes #16520.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/cookies.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 5b3c0e7316..83ac62a83d 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -3,6 +3,7 @@ require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/object/blank'
require 'active_support/key_generator'
require 'active_support/message_verifier'
+require 'active_support/json'
module ActionDispatch
class Request < Rack::Request
@@ -391,11 +392,11 @@ module ActionDispatch
class JsonSerializer
def self.load(value)
- JSON.parse(value, quirks_mode: true)
+ ActiveSupport::JSON.decode(value)
end
def self.dump(value)
- JSON.generate(value, quirks_mode: true)
+ ActiveSupport::JSON.encode(value)
end
end