File tree Expand file tree Collapse file tree 4 files changed +37
-0
lines changed
lib/active_support/message_pack Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ * The Cookie Serializer can now serialize an Active Support SafeBuffer when using message pack.
2
+
3
+ Such code would previously produce an error if an application was using messagepack as its cookie serializer.
4
+
5
+ ``` ruby
6
+ class PostController < ApplicationController
7
+ def index
8
+ flash.notice = t(:hello_html ) # This would try to serialize a SafeBuffer, which was not possible.
9
+ end
10
+ end
11
+ ```
12
+
13
+ * Edouard Chin *
14
+
1
15
* Fix ` Rails.application.reload_routes!` from clearing almost all routes.
2
16
3
17
When calling ` Rails.application.reload_routes!` inside a middleware of
Original file line number Diff line number Diff line change @@ -263,6 +263,11 @@ def set_flash
263
263
head :ok
264
264
end
265
265
266
+ def set_html_flash
267
+ flash [ "that" ] = ActiveSupport ::SafeBuffer . new ( "<p>Hello world</p>" )
268
+ head :ok
269
+ end
270
+
266
271
def set_flash_now
267
272
flash . now [ "that" ] = "hello"
268
273
head :ok
@@ -297,6 +302,18 @@ def test_flash
297
302
end
298
303
end
299
304
305
+ def test_flash_safebuffer
306
+ with_test_route_set do
307
+ get "/set_html_flash" , env : { "action_dispatch.cookies_serializer" => :message_pack }
308
+ assert_response :success
309
+ assert_equal "<p>Hello world</p>" , @request . flash [ "that" ]
310
+
311
+ get "/use_flash" , env : { "action_dispatch.cookies_serializer" => :message_pack }
312
+ assert_response :success
313
+ assert_equal "flash: <p>Hello world</p>" , @response . body
314
+ end
315
+ end
316
+
300
317
def test_just_using_flash_does_not_stream_a_cookie_back
301
318
with_test_route_set do
302
319
get "/use_flash"
Original file line number Diff line number Diff line change 7
7
require "uri/generic"
8
8
require "msgpack/bigint"
9
9
require "active_support/hash_with_indifferent_access"
10
+ require "active_support/core_ext/string/output_safety"
10
11
require "active_support/time"
11
12
12
13
module ActiveSupport
@@ -102,6 +103,10 @@ def install(registry)
102
103
packer : method ( :write_hash_with_indifferent_access ) ,
103
104
unpacker : method ( :read_hash_with_indifferent_access ) ,
104
105
recursive : true
106
+
107
+ registry . register_type 18 , ActiveSupport ::SafeBuffer ,
108
+ packer : :to_s ,
109
+ unpacker : :new
105
110
end
106
111
107
112
def install_unregistered_type_error ( registry )
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ module MessagePackSharedSerializerTests
24
24
15 => Pathname ,
25
25
16 => Regexp ,
26
26
17 => ActiveSupport ::HashWithIndifferentAccess ,
27
+ 18 => ActiveSupport ::SafeBuffer ,
27
28
127 => Object ,
28
29
}
29
30
You can’t perform that action at this time.
0 commit comments