From 6dc92ff6c6647d22e190b0f9946300720b94518b Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Fri, 14 Aug 2026 17:29:38 +0900 Subject: [PATCH] Stop treating Adobe Illustrator files as PDF files while keeping their thumbnails (#44335) --- app/controllers/attachments_controller.rb | 4 ++-- app/models/attachment.rb | 5 ++++- lib/redmine/mime_type.rb | 2 ++ test/unit/attachment_test.rb | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b2619aa34..7cbfc3cd3 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -300,8 +300,8 @@ class AttachmentsController < ApplicationController "application/octet-stream" end - if is_thumb && content_type == "application/pdf" - # PDF previews are stored in PNG format + if is_thumb && !content_type.start_with?("image/") + # Thumbnails of non-image files are stored in PNG format content_type = "image/png" end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 4d9974dce..b085a919f 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -232,7 +232,10 @@ class Attachment < ApplicationRecord def thumbnailable? Redmine::Thumbnail.convert_available? && ( - image? || (is_pdf? && Redmine::Thumbnail.gs_available?) + image? || + (Redmine::Thumbnail.gs_available? && + # Illustrator files are often PDF compatible + ['application/pdf', 'application/illustrator'].include?(Redmine::MimeType.of(filename))) ) end diff --git a/lib/redmine/mime_type.rb b/lib/redmine/mime_type.rb index 170264715..4e30ab4f0 100644 --- a/lib/redmine/mime_type.rb +++ b/lib/redmine/mime_type.rb @@ -46,6 +46,8 @@ module Redmine 'image/tiff' => 'tiff,tif', 'image/webp' => 'webp', 'image/x-ms-bmp' => 'bmp', + # Not registered with IANA, but matches Marcel's type for .ai + 'application/illustrator' => 'ai', 'application/javascript' => 'js', 'application/pdf' => 'pdf', 'video/mp4' => 'mp4', diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index a7f456a35..e9d5808b4 100644 --- a/test/unit/attachment_test.rb +++ b/test/unit/attachment_test.rb @@ -574,6 +574,12 @@ class AttachmentTest < ActiveSupport::TestCase assert_equal false, Attachment.new(:filename => 'test.txt').thumbnailable? end + def test_thumbnailable_should_be_true_for_illustrator_files + Redmine::Thumbnail.stubs(:convert_available?).returns(true) + Redmine::Thumbnail.stubs(:gs_available?).returns(true) + assert_equal true, Attachment.new(:filename => 'test.ai').thumbnailable? + end + def test_markdownized_previewable_should_be_true_for_supported_extensions skip unless Redmine::Markdownizer.available? @@ -768,4 +774,16 @@ class AttachmentTest < ActiveSupport::TestCase assert_equal expected, attachment.is_text?, attachment.inspect end end + + def test_is_pdf + to_test = { + 'report.pdf' => true, + # Illustrator files are not PDF files, even though some of them are + # PDF compatible + 'logo.ai' => false, + } + to_test.each do |filename, expected| + assert_equal expected, Attachment.new(:filename => filename).is_pdf?, filename + end + end end -- 2.50.1