diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-05-20 16:16:48 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-05-20 18:22:37 +0200 |
commit | 98f12863469323c589f176f9cc24b8efc5308e3a (patch) | |
tree | 99a33fdc5ad51c182fd4174c38c560b56c453c47 | |
parent | 65c89b4208675156520f5cee6cba479f1a1c1455 (diff) | |
download | gitlab-ce-98f12863469323c589f176f9cc24b8efc5308e3a.tar.gz |
Merge branch 'lexer_error_workaround' into 'master'
workaround for buggy lexers
It seems that some lexers can be buggy when used together with git blame.
This results in a 500 error when a user tries to open the blame page in some cases.
The workaround is pretty simple. Not only fall back to plaintext when the file content can't be guessed, but also when the lexer fails.
This closes #1521 and #1646
/cc @DouweM @JobV It would be awesome to have this in a patch release for 7.11 or even in the release. But that's probably to late.
See merge request !683
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/helpers/blob_helper.rb | 6 |
2 files changed, 5 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index f92f486064f..969aa210843 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.11.0 (unreleased) + - Fall back to Plaintext when Syntaxhighlighting doesn't work. Fixes some buggy lexers (Hannes Rosenögger) - Fix broken view when viewing history of a file that includes a path that used to be another file (Stan Hu) - Don't show duplicate deploy keys - Fix commit time being displayed in the wrong timezone in some cases (Hannes Rosenögger) diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 4ea838ca447..e01d6e50344 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -9,11 +9,13 @@ module BlobHelper begin lexer = Rugments::Lexer.guess(filename: blob_name, source: blob_content) - rescue Rugments::Lexer::AmbiguousGuess + result = formatter.format(lexer.lex(blob_content)).html_safe + rescue lexer = Rugments::Lexers::PlainText + result = formatter.format(lexer.lex(blob_content)).html_safe end - formatter.format(lexer.lex(blob_content)).html_safe + result end def no_highlight_files |