Commit 80f8cb2f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parents e794b561 8265d43d
...@@ -221,7 +221,8 @@ module ApplicationHelper ...@@ -221,7 +221,8 @@ module ApplicationHelper
end end
def render_markup(file_name, file_content) 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 rescue RuntimeError
simple_format(file_content) simple_format(file_content)
end end
......
...@@ -217,4 +217,13 @@ describe ApplicationHelper do ...@@ -217,4 +217,13 @@ describe ApplicationHelper do
).to eq("<a href=\"http://www.example.com\" rel=\"noreferrer nofollow\">Example</a>") ).to eq("<a href=\"http://www.example.com\" rel=\"noreferrer nofollow\">Example</a>")
end end
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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment