From 8265d43d016d4bcd67ce1f7cb452a239953cf8bd Mon Sep 17 00:00:00 2001
From: Robert Schilling <rschilling@student.tugraz.at>
Date: Thu, 31 Jul 2014 11:22:46 +0200
Subject: [PATCH] Force of markup output to be the input encoding

---
 app/helpers/application_helper.rb       | 3 ++-
 spec/helpers/application_helper_spec.rb | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index cc49b89191bbb..e6d50bea4d1fe 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 510b76fa9dfdf..2db67cfdf95e1 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
-- 
GitLab