diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cc49b89191bbb56be9d2e1289fd64984f45fd3de..e6d50bea4d1fe2ca2a72a225f844d2bd9ece73be 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -221,7 +221,8 @@ def time_ago_with_tooltip(date, placement = 'top', html_class = 'time_ago') end def render_markup(file_name, file_content) - GitHub::Markup.render(file_name, file_content).html_safe + GitHub::Markup.render(file_name, file_content). + force_encoding(file_content.encoding).html_safe rescue RuntimeError simple_format(file_content) end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 510b76fa9dfdfac285f3189c4dbb57cab875314e..2db67cfdf95e11c9d9947c99b0d3f5805a9ab74b 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -217,4 +217,13 @@ def grouped_options_for_select(options, *args) ).to eq("<a href=\"http://www.example.com\" rel=\"noreferrer nofollow\">Example</a>") end end + + describe 'markup_render' do + let(:content) { 'Noël' } + + it 'should preserve encoding' do + content.encoding.name.should == 'UTF-8' + expect(render_markup('foo.rst', content).encoding.name).to eq('UTF-8') + end + end end