diff --git a/lib/redmine/syntax_highlighting.rb b/lib/redmine/syntax_highlighting.rb index e2d47f277..36612bc8c 100644 --- a/lib/redmine/syntax_highlighting.rb +++ b/lib/redmine/syntax_highlighting.rb @@ -76,6 +76,7 @@ module Redmine # Highlights +text+ as the content of +filename+ # Should not return line numbers nor outer pre tag def highlight_by_filename(text, filename) + text.gsub!(/\r\n?/, "\n") lexer =::Rouge::Lexer.guess_by_filename(filename) formatter = ::Rouge::Formatters::HTML.new ::Rouge.highlight(text, lexer, CustomHTMLLinewise.new(formatter)) @@ -92,7 +93,7 @@ module Redmine def language_supported?(language) find_lexer(language.to_s.downcase) ? true : false end - + private # Alias names used by CodeRay and not supported by Rouge LANG_ALIASES = { diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 5561e2f40..db7a8f123 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1123,6 +1123,10 @@ EXPECTED end end + def test_syntax_highlight_should_remove_cr_chars + assert_equal "line 1\nline 2\n", syntax_highlight(nil, "line 1\rline 2\r\n") + end + def test_to_path_param assert_equal 'test1/test2', to_path_param('test1/test2') assert_equal 'test1/test2', to_path_param('/test1/test2/')