BigW Consortium Gitlab

Commit b8c05a06 by Robert Schilling

Merge branch 'rescue-syntax-highlighting-errors' into 'master'

Gracefully handle errors in syntax highlighting by leaving the block unformatted A bug in Rouge caused an Exception: ```undefined method `sub' for :Literal:Symbol``` That caused https://gitlab.com/embeddable-common-lisp/ecl/issues/156 to hit Error 500 and fail to display. If a failure occurs, just render the text as preformatted. Closes #2433 See merge request !1274
parents 0a2c7fcc 9d3344ad
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.0.0 (unreleased) v 8.0.0 (unreleased)
- Gracefully handle errors in syntax highlighting by leaving the block unformatted (Stan Hu)
- Fix URL construction for merge requests, issues, notes, and commits for relative URL config (Stan Hu) - Fix URL construction for merge requests, issues, notes, and commits for relative URL config (Stan Hu)
- Fix emoji URLs in Markdown when relative_url_root is used (Stan Hu) - Fix emoji URLs in Markdown when relative_url_root is used (Stan Hu)
- Omit filename in Content-Disposition header in raw file download to avoid RFC 6266 encoding issues (Stan HU) - Omit filename in Content-Disposition header in raw file download to avoid RFC 6266 encoding issues (Stan HU)
......
...@@ -21,7 +21,11 @@ module Gitlab ...@@ -21,7 +21,11 @@ module Gitlab
language = node.attr('class') language = node.attr('class')
code = node.text code = node.text
begin
highlighted = block_code(code, language) highlighted = block_code(code, language)
rescue
highlighted = "<pre>#{code}</pre>"
end
# Replace the parent `pre` element with the entire highlighted block # Replace the parent `pre` element with the entire highlighted block
node.parent.replace(highlighted) node.parent.replace(highlighted)
......
require 'spec_helper'
module Gitlab::Markdown
describe SyntaxHighlightFilter do
include FilterSpecHelper
let(:project) { create(:empty_project) }
let(:reference) { snippet.to_reference }
it 'highlights valid code blocks' do
result = filter('<pre><code>def fun end</code>')
expect(result.to_html).to eq("<pre class=\"code highlight js-syntax-highlight plaintext\"><code>def fun end</code></pre>\n")
end
it 'passes through invalid code blocks' do
allow_any_instance_of(SyntaxHighlightFilter).to receive(:block_code).and_raise(StandardError)
result = filter('<pre><code>This is a test</code></pre>')
expect(result.to_html).to eq('<pre>This is a test</pre>')
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