From 185af09f47ba79857920898db5942200b07eeb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Fern=C3=A1ndez=20Capel?= Date: Fri, 9 Apr 2010 02:00:04 +0200 Subject: [PATCH] Force ERB generated source to be in default external encoding. See ticket 2188 (Encoding error in Ruby1.9 for templates) --- .../lib/action_view/template_handlers/erb.rb | 1 + actionpack/test/fixtures/test/utf8.html.erb | 1 + actionpack/test/template/render_test.rb | 2 +- 3 files changed, 3 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/template_handlers/erb.rb b/actionpack/lib/action_view/template_handlers/erb.rb index e3120ba..c1a0849 100644 --- a/actionpack/lib/action_view/template_handlers/erb.rb +++ b/actionpack/lib/action_view/template_handlers/erb.rb @@ -12,6 +12,7 @@ module ActionView def compile(template) src = ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src + src.force_encoding(Encoding.default_external) if src.respond_to? :force_encoding # Ruby 1.9 prepends an encoding to the source. However this is # useless because you can only set an encoding on the first line diff --git a/actionpack/test/fixtures/test/utf8.html.erb b/actionpack/test/fixtures/test/utf8.html.erb index 0b4d19a..d99f47e 100644 --- a/actionpack/test/fixtures/test/utf8.html.erb +++ b/actionpack/test/fixtures/test/utf8.html.erb @@ -1,2 +1,3 @@ Русский текст +<%= "mañana" %> 日本語のテキスト \ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 9adf053..2a1ba90 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -251,7 +251,7 @@ 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 + assert_equal "Русский текст\nmañana\n日本語のテキスト", result assert_equal Encoding::UTF_8, result.encoding end end -- 1.6.5.2