From d5fcb5b9ad4ecb271834ee5a689a1ead40290086 Mon Sep 17 00:00:00 2001 From: Ufuk Kayserilioglu Date: Thu, 24 Jan 2019 22:08:02 +0200 Subject: Revert "Allow usage of strings as locals for partial renderer" --- actionview/lib/action_view/renderer/partial_renderer.rb | 2 +- actionview/test/actionpack/controller/render_test.rb | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index cb850d75ee..f175c30aa1 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -363,7 +363,7 @@ module ActionView @options = options @block = block - @locals = options[:locals] ? options[:locals].symbolize_keys : {} + @locals = options[:locals] || {} @details = extract_details(options) prepend_formats(options[:formats]) diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index 204903c60c..02df84da8e 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -485,10 +485,6 @@ class TestController < ActionController::Base render partial: "customer", locals: { customer: Customer.new("david") } end - def partial_with_string_locals - render partial: "customer", locals: { "customer" => Customer.new("david") } - end - def partial_with_form_builder render partial: ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {}) end @@ -691,7 +687,6 @@ class RenderTest < ActionController::TestCase get :partial_with_locals, to: "test#partial_with_locals" get :partial_with_nested_object, to: "test#partial_with_nested_object" get :partial_with_nested_object_shorthand, to: "test#partial_with_nested_object_shorthand" - get :partial_with_string_locals, to: "test#partial_with_string_locals" get :partials_list, to: "test#partials_list" get :render_action_hello_world, to: "test#render_action_hello_world" get :render_action_hello_world_as_string, to: "test#render_action_hello_world_as_string" @@ -1292,11 +1287,6 @@ class RenderTest < ActionController::TestCase assert_equal "Hello: david", @response.body end - def test_partial_with_string_locals - get :partial_with_string_locals - assert_equal "Hello: david", @response.body - end - def test_partial_with_form_builder get :partial_with_form_builder assert_equal "\n", @response.body -- cgit v1.2.3 From 44c07fd0be1368f8388669f9d660b75eb8e49ac9 Mon Sep 17 00:00:00 2001 From: Ufuk Kayserilioglu Date: Thu, 24 Jan 2019 22:41:19 +0200 Subject: Add test for Hash-like object being passed to partial `locals` The test passes an instance of `ActionController::Parameters` that acts like a Hash but does not respond to some Hash methods like `symbolize_keys`. Moreover, if someone were to call `to_h` on the value it would fail since the parameter is not permitted. So this is a great way to ensure that the partial rendering pipeline does not mess with `locals`. --- actionview/test/actionpack/controller/render_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index 02df84da8e..727d3fbc1a 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -485,6 +485,10 @@ class TestController < ActionController::Base render partial: "customer", locals: { customer: Customer.new("david") } end + def partial_with_hashlike_locals + render partial: "customer", locals: ActionController::Parameters.new(customer: Customer.new("david")) + end + def partial_with_form_builder render partial: ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {}) end @@ -687,6 +691,7 @@ class RenderTest < ActionController::TestCase get :partial_with_locals, to: "test#partial_with_locals" get :partial_with_nested_object, to: "test#partial_with_nested_object" get :partial_with_nested_object_shorthand, to: "test#partial_with_nested_object_shorthand" + get :partial_with_hashlike_locals, to: "test#partial_with_hashlike_locals" get :partials_list, to: "test#partials_list" get :render_action_hello_world, to: "test#render_action_hello_world" get :render_action_hello_world_as_string, to: "test#render_action_hello_world_as_string" @@ -1287,6 +1292,11 @@ class RenderTest < ActionController::TestCase assert_equal "Hello: david", @response.body end + def test_partial_with_hashlike_locals + get :partial_with_hashlike_locals + assert_equal "Hello: david", @response.body + end + def test_partial_with_form_builder get :partial_with_form_builder assert_equal "\n", @response.body -- cgit v1.2.3