Permalink
Browse files

Expect an incompatible encoding exception when a template with a magi…

…c comment renders a partial without one and its source encoding doesn't match the default external encoding
  • Loading branch information...
1 parent bd2bf53 commit 4691c696b0cda985c5d868312555cd538328a99c @jeremy jeremy committed Apr 9, 2010
@@ -0,0 +1 @@
+<%= "текст" %>
@@ -0,0 +1,2 @@
+<%# encoding: utf-8 -%>
+<%= "текст" %>
@@ -1,4 +1,4 @@
-Русский <%= "текст" %>
+Русский <%= render :partial => 'test/utf8_partial' %>
<%= "".encoding %>
<%= @output_buffer.encoding %>
<%= __ENCODING__ %>
@@ -1,5 +1,5 @@
<%# encoding: utf-8 -%>
-Русский <%= "текст" %>
+Русский <%= render :partial => 'test/utf8_partial_magic' %>
<%= "".encoding %>
<%= @output_buffer.encoding %>
<%= __ENCODING__ %>
@@ -0,0 +1,5 @@
+<%# encoding: utf-8 -%>
+Русский <%= render :partial => 'test/utf8_partial' %>
+<%= "".encoding %>
+<%= @output_buffer.encoding %>
+<%= __ENCODING__ %>
@@ -283,15 +283,15 @@ def test_render_utf8_template_with_magic_comment
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
def test_render_utf8_template_with_default_external_encoding
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 @@ def test_render_utf8_template_with_incompatible_external_encoding
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

0 comments on commit 4691c69

Please sign in to comment.