From 2633593b23870398848f0627abdf65e8e5074eb8 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Johan=20S=C3=B8rensen?= Date: Mon, 16 Feb 2009 14:05:24 +0100 Subject: [PATCH] Make partial rendering from within a content_for capture work with ruby 1.9 encodings --- actionpack/lib/action_view/renderable.rb | 2 +- .../test/fixtures/test/content_for_utf8.html.erb | 5 +++++ actionpack/test/template/render_test.rb | 12 ++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 actionpack/test/fixtures/test/content_for_utf8.html.erb diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index 41080ed..a095a42 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -71,7 +71,7 @@ module ActionView source = <<-end_src def #{render_symbol}(local_assigns) - old_output_buffer = output_buffer;#{locals_code};#{compiled_source} + old_output_buffer = output_buffer;#{locals_code};#{compiled_source.respond_to?(:force_encoding) ? compiled_source.force_encoding(Encoding::UTF_8) : compiled_source} ensure self.output_buffer = old_output_buffer end diff --git a/actionpack/test/fixtures/test/content_for_utf8.html.erb b/actionpack/test/fixtures/test/content_for_utf8.html.erb new file mode 100644 index 0000000..3a91f38 --- /dev/null +++ b/actionpack/test/fixtures/test/content_for_utf8.html.erb @@ -0,0 +1,5 @@ +<% content_for :title do -%> +Русский текст +<%= render :partial => "test/partial_for_use_in_layout", :locals => {:name => " 日本語のテキスト"} -%> +<% end -%> +yay? \ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 107c625..63f1a9f 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -236,10 +236,18 @@ module RenderTestCases if '1.9'.respond_to?(:force_encoding) def test_render_utf8_template - result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield") - assert_equal "Русский текст\n日本語のテキスト", result + result = @view.render(:file => "test/utf8.html.erb", :layout => "layouts/yield") + assert_equal "\nРусский текст\n日本語のテキスト\n", result assert_equal Encoding::UTF_8, result.encoding end + + def test_render_utf8_template_with_named_yield_and_a_partial + assert_nothing_raised do + result = @view.render(:file => "test/content_for_utf8.html.erb", :layout => "layouts/yield") + assert_equal "Русский текст\nInside from partial ( 日本語のテキスト)\nyay?\n", result + assert_equal Encoding::UTF_8, result.encoding + end + end end end -- 1.6.1