Index: lib/redmine/syntax_highlighting.rb =================================================================== --- lib/redmine/syntax_highlighting.rb (リビジョン 18114) +++ lib/redmine/syntax_highlighting.rb (作業コピー) @@ -85,7 +85,7 @@ # See also: https://github.com/jneen/rouge/pull/1078 text = text.gsub(/\r\n?/, "\n") - lexer =::Rouge::Lexer.guess_by_filename(filename) + lexer =::Rouge::Lexer.guess(:source => text, :filename => filename) formatter = ::Rouge::Formatters::HTML.new ::Rouge.highlight(text, lexer, CustomHTMLLinewise.new(formatter)) end Index: test/unit/lib/redmine/syntax_highlighting/rouge_test.rb =================================================================== --- test/unit/lib/redmine/syntax_highlighting/rouge_test.rb (nonexistent) +++ test/unit/lib/redmine/syntax_highlighting/rouge_test.rb (作業コピー) @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2017 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../../../test_helper', __FILE__) + +class Redmine::SyntaxHighlighting::RougeTest < ActiveSupport::TestCase + def test_highlight_by_filename_should_distinguish_perl_and_prolog + code_perl, code_prolog = <<'PERL', <<'PROLOG' +#!/usr/bin/perl +print "Hello, world!\n"; +PERL +#!/usr/bin/swipl +:- writeln('Hello, world!'),halt. +PROLOG + filename = 'hello.pl' + + assert_equal Rouge::Lexers::Perl, Rouge::Lexer.guess(:filename => filename, :source => code_perl) + assert_equal Rouge::Lexers::Prolog, Rouge::Lexer.guess(:filename => filename, :source => code_prolog) + + # Rouge raises Rouge::Guesser::Ambiguous exception if it cannot decide + # between prolog and perl + assert_nothing_raised do + html = Redmine::SyntaxHighlighting::Rouge.highlight_by_filename(code_perl, filename) + assert_match '