Project

General

Profile

Defect #29259 » 0002-Attachment-preview-does-not-support-source-code-in-s.patch

Go MAEDA, 2019-05-02 08:38

View differences:

app/models/attachment.rb
end
def is_text?
Redmine::MimeType.is_type?('text', filename)
Redmine::MimeType.is_type?('text', filename) || Redmine::SyntaxHighlighting.filename_supported?(filename)
end
def is_image?
lib/redmine/syntax_highlighting.rb
rescue
false
end
def filename_supported?(filename)
if highlighter.respond_to? :filename_supported?
highlighter.filename_supported? filename
else
false
end
end
end
module Rouge
......
def language_supported?(language)
find_lexer(language.to_s.downcase) ? true : false
end
def filename_supported?(filename)
!::Rouge::Lexer.guesses(:filename => filename).empty?
end
private
# Alias names used by CodeRay and not supported by Rouge
test/fixtures/files/hello.js
document.write('Hello, World!');
test/unit/attachment_test.rb
puts '(ImageMagick convert not available)'
end
def test_is_text
js_attachment = Attachment.new(
:container => Issue.find(1),
:file => uploaded_test_file('hello.js', 'application/javascript'),
:author => User.find(1))
to_test = {
js_attachment => true, # hello.js (application/javascript)
attachments(:attachments_003) => false, # logo.gif (image/gif)
attachments(:attachments_004) => true, # source.rb (application/x-ruby)
attachments(:attachments_015) => true, # private.diff (text/x-diff)
attachments(:attachments_016) => false, # testfile.png (image/png)
}
to_test.each do |attachment, expected|
assert_equal expected, attachment.is_text?
end
end
end
test/unit/lib/redmine/syntax_highlighting/rouge_test.rb
require File.expand_path('../../../../../test_helper', __FILE__)
class Redmine::SyntaxHighlighting::RougeTest < ActiveSupport::TestCase
def test_filename_supported
to_test = {
'application.js' => true,
'Gemfile' => true,
'AUTOEXEC.BAT' => false,
'HELLO.C' => true
}
to_test.each do |filename, expected|
assert_equal expected, Redmine::SyntaxHighlighting::Rouge.filename_supported?(filename)
end
end
def test_highlight_by_filename_should_distinguish_perl_and_prolog
raw_perl = <<'RAW_PERL'
#!/usr/bin/perl
(3-3/3)