summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-08-11 10:20:34 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-08-11 10:20:34 +0000
commit80f8cb2f8844566cda41529a2b0fd4b75eb3080d (patch)
tree4b09eaa8b1f86e8503badf57584117b25489d8f1
parente794b561330070465a67ec57bc65069e12b78ef5 (diff)
parent8265d43d016d4bcd67ce1f7cb452a239953cf8bd (diff)
downloadgitlab-ce-80f8cb2f8844566cda41529a2b0fd4b75eb3080d.tar.gz
Merge branch 'fix_markup_encoding' into 'master'
Fix encoding of output of markup, prevent 500 for non-ascii characters #### What does this MR do? This MR forces the output of `Github::markup` to have the same encoding as the input to it. #### Why was this MR needed? This prevents 500 errors if the markup contains non-asci characters. #### What are the relevant issue numbers / Feature requests? This MR closes * #296 * https://github.com/gitlabhq/gitlabhq/issues/7023 /cc @jacobvosmaer See merge request !160
-rw-r--r--app/helpers/application_helper.rb3
-rw-r--r--spec/helpers/application_helper_spec.rb9
2 files changed, 11 insertions, 1 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index cc49b89191b..e6d50bea4d1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -221,7 +221,8 @@ module ApplicationHelper
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 510b76fa9df..2db67cfdf95 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -217,4 +217,13 @@ describe ApplicationHelper do
).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