From 4691c696b0cda985c5d868312555cd538328a99c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 8 Apr 2010 20:22:07 -0700 Subject: Expect an incompatible encoding exception when a template with a magic comment renders a partial without one and its source encoding doesn't match the default external encoding --- actionpack/test/fixtures/test/_utf8_partial.html.erb | 1 + .../test/fixtures/test/_utf8_partial_magic.html.erb | 2 ++ actionpack/test/fixtures/test/utf8.html.erb | 2 +- actionpack/test/fixtures/test/utf8_magic.html.erb | 2 +- .../fixtures/test/utf8_magic_with_bare_partial.html.erb | 5 +++++ actionpack/test/template/render_test.rb | 15 +++++++++++++-- 6 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 actionpack/test/fixtures/test/_utf8_partial.html.erb create mode 100644 actionpack/test/fixtures/test/_utf8_partial_magic.html.erb create mode 100644 actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb diff --git a/actionpack/test/fixtures/test/_utf8_partial.html.erb b/actionpack/test/fixtures/test/_utf8_partial.html.erb new file mode 100644 index 0000000000..8d717fd427 --- /dev/null +++ b/actionpack/test/fixtures/test/_utf8_partial.html.erb @@ -0,0 +1 @@ +<%= "текст" %> diff --git a/actionpack/test/fixtures/test/_utf8_partial_magic.html.erb b/actionpack/test/fixtures/test/_utf8_partial_magic.html.erb new file mode 100644 index 0000000000..4e2224610a --- /dev/null +++ b/actionpack/test/fixtures/test/_utf8_partial_magic.html.erb @@ -0,0 +1,2 @@ +<%# encoding: utf-8 -%> +<%= "текст" %> diff --git a/actionpack/test/fixtures/test/utf8.html.erb b/actionpack/test/fixtures/test/utf8.html.erb index 551c24e354..ac98c2f012 100644 --- a/actionpack/test/fixtures/test/utf8.html.erb +++ b/actionpack/test/fixtures/test/utf8.html.erb @@ -1,4 +1,4 @@ -Русский <%= "текст" %> +Русский <%= render :partial => 'test/utf8_partial' %> <%= "日".encoding %> <%= @output_buffer.encoding %> <%= __ENCODING__ %> diff --git a/actionpack/test/fixtures/test/utf8_magic.html.erb b/actionpack/test/fixtures/test/utf8_magic.html.erb index e2aa85e66a..257279c29f 100644 --- a/actionpack/test/fixtures/test/utf8_magic.html.erb +++ b/actionpack/test/fixtures/test/utf8_magic.html.erb @@ -1,5 +1,5 @@ <%# encoding: utf-8 -%> -Русский <%= "текст" %> +Русский <%= render :partial => 'test/utf8_partial_magic' %> <%= "日".encoding %> <%= @output_buffer.encoding %> <%= __ENCODING__ %> diff --git a/actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb b/actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb new file mode 100644 index 0000000000..cb22692f9a --- /dev/null +++ b/actionpack/test/fixtures/test/utf8_magic_with_bare_partial.html.erb @@ -0,0 +1,5 @@ +<%# encoding: utf-8 -%> +Русский <%= render :partial => 'test/utf8_partial' %> +<%= "日".encoding %> +<%= @output_buffer.encoding %> +<%= __ENCODING__ %> diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 647c673902..c9a50da418 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -283,7 +283,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase with_external_encoding Encoding::ASCII_8BIT do result = @view.render(:file => "test/utf8_magic.html.erb", :layouts => "layouts/yield") assert_equal Encoding::UTF_8, result.encoding - assert_equal "Русский текст\nUTF-8\nUTF-8\nUTF-8\n", result + assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result end end @@ -291,7 +291,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase with_external_encoding Encoding::UTF_8 do result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield") assert_equal Encoding::UTF_8, result.encoding - assert_equal "Русский текст\nUTF-8\nUTF-8\nUTF-8\n", result + assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result end end @@ -306,6 +306,17 @@ class LazyViewRenderTest < ActiveSupport::TestCase end end + def test_render_utf8_template_with_partial_with_incompatible_encoding + with_external_encoding Encoding::SJIS do + begin + result = @view.render(:file => "test/utf8_magic_with_bare_partial.html.erb", :layouts => "layouts/yield") + flunk 'Should have raised incompatible encoding error' + rescue ActionView::Template::Error => error + assert_match 'invalid byte sequence in Shift_JIS', error.original_exception.message + end + end + end + def with_external_encoding(encoding) old, Encoding.default_external = Encoding.default_external, encoding yield -- cgit v1.2.3