Project

General

Profile

Defect #44335 » 0001-Stop-treating-Adobe-Illustrator-files-as-PDF-files-w.patch

Go MAEDA, 2026-08-15 10:46

View differences:

app/controllers/attachments_controller.rb
300 300
        "application/octet-stream"
301 301
    end
302 302

  
303
    if is_thumb && content_type == "application/pdf"
304
      # PDF previews are stored in PNG format
303
    if is_thumb && !content_type.start_with?("image/")
304
      # Thumbnails of non-image files are stored in PNG format
305 305
      content_type = "image/png"
306 306
    end
307 307

  
app/models/attachment.rb
232 232

  
233 233
  def thumbnailable?
234 234
    Redmine::Thumbnail.convert_available? && (
235
      image? || (is_pdf? && Redmine::Thumbnail.gs_available?)
235
      image? ||
236
        (Redmine::Thumbnail.gs_available? &&
237
         # Illustrator files are often PDF compatible
238
         ['application/pdf', 'application/illustrator'].include?(Redmine::MimeType.of(filename)))
236 239
    )
237 240
  end
238 241

  
lib/redmine/mime_type.rb
46 46
      'image/tiff' => 'tiff,tif',
47 47
      'image/webp' => 'webp',
48 48
      'image/x-ms-bmp' => 'bmp',
49
      # Not registered with IANA, but matches Marcel's type for .ai
50
      'application/illustrator' => 'ai',
49 51
      'application/javascript' => 'js',
50 52
      'application/pdf' => 'pdf',
51 53
      'video/mp4' => 'mp4',
test/unit/attachment_test.rb
574 574
    assert_equal false, Attachment.new(:filename => 'test.txt').thumbnailable?
575 575
  end
576 576

  
577
  def test_thumbnailable_should_be_true_for_illustrator_files
578
    Redmine::Thumbnail.stubs(:convert_available?).returns(true)
579
    Redmine::Thumbnail.stubs(:gs_available?).returns(true)
580
    assert_equal true, Attachment.new(:filename => 'test.ai').thumbnailable?
581
  end
582

  
577 583
  def test_markdownized_previewable_should_be_true_for_supported_extensions
578 584
    skip unless Redmine::Markdownizer.available?
579 585

  
......
768 774
      assert_equal expected, attachment.is_text?, attachment.inspect
769 775
    end
770 776
  end
777

  
778
  def test_is_pdf
779
    to_test = {
780
      'report.pdf' => true,
781
      # Illustrator files are not PDF files, even though some of them are
782
      # PDF compatible
783
      'logo.ai' => false,
784
    }
785
    to_test.each do |filename, expected|
786
      assert_equal expected, Attachment.new(:filename => filename).is_pdf?, filename
787
    end
788
  end
771 789
end
(2-2/2)