From 93ca543d2219b05fe3a9e9bb574652b1781a4392 Mon Sep 17 00:00:00 2001 From: Tony Pitale Date: Fri, 15 Aug 2008 11:20:32 -0400 Subject: [PATCH] partials and templates silently strip spaces from the option --- actionpack/lib/action_controller/base.rb | 3 +++ actionpack/test/controller/new_render_test.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 0fdbcbd..5ce0a1a 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -890,6 +890,7 @@ module ActionController #:nodoc: render_for_file(file, options[:status], nil, options[:locals] || {}) elsif template = options[:template] + template.strip! if template render_for_file(template, options[:status], true, options[:locals] || {}) elsif inline = options[:inline] @@ -915,7 +916,9 @@ module ActionController #:nodoc: render_for_text(json, options[:status]) elsif partial = options[:partial] + partial.strip! if partial && partial.kind_of?(String) partial = default_template_name if partial == true + add_variables_to_assigns if collection = options[:collection] diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb index be99350..bccffb3 100644 --- a/actionpack/test/controller/new_render_test.rb +++ b/actionpack/test/controller/new_render_test.rb @@ -135,6 +135,10 @@ class NewRenderTestController < ActionController::Base def partial_only_with_layout render :partial => "partial_only", :layout => true end + + def partial_with_spaces + render :partial => " partial_only " + end def partial_with_counter render :partial => "counter", :locals => { :counter_counter => 5 } @@ -275,6 +279,10 @@ class NewRenderTestController < ActionController::Base def render_with_explicit_template render :template => "test/hello_world" end + + def template_with_spaces + render :template => " test/hello_world " + end def render_with_explicit_template_with_locals render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' } @@ -716,6 +724,11 @@ EOS get :render_with_explicit_template assert_response :success end + + def test_render_template_with_spaces + get :template_with_spaces + assert_response :success + end def test_double_render assert_raises(ActionController::DoubleRenderError) { get :double_render } @@ -954,6 +967,11 @@ EOS get :render_call_to_partial_with_layout assert_equal "Before (David)\nInside from partial (David)\nAfter", @response.body end + + def test_render_partial_with_spaces + get :partial_with_spaces + assert_equal "only partial", @response.body + end def test_render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout -- 1.5.5