Defect #31275

Safari adds .html extension when downloading files of unknown type

Added by Christian Felix 21 days ago. Updated 20 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Attachments
Target version:4.0.4
Resolution:Fixed Affected version:4.0.3

Description

Redmine Version: 4.0.3.stable
Browser Version: Safari 12.1
Operating system: macOS 10.14.4

What is the issue and how can it be reproduced?

This problem only seems to happen in the Safari browser. When trying to download a "irregular" file such as .indd, .idml, etc. from Redmine, it always adds a .html at the end of the file. Downloading a picture file (.jpeg .png .gif etc.) for example, is working perfectly fine and does not get the .html at the end of the filename.

It looks like Redmine adds either the wrong content-type or none at all which may lead to this issue in Safari.

What is the expected behavior?

When downloading any type of file from Redmine with Safari, it should always download the file as is and not add anything at the end of the filename.

Additional info:

At first I thought that it was an issue with Safari as it was working perfectly fine in Chrome or Firefox but as regular files are working in Safari as well, I kind of think that this is a combined issue of Redmine and Safari. (Safari being too straight with file types)

Associated revisions

Revision 18098
Added by Go MAEDA 20 days ago

Fix that Content-Type header field is empty when sending a file of unknown type (#31275).

Patch by Go MAEDA.

Revision 18099
Added by Go MAEDA 20 days ago

Correct the fixture id (#31275).

Revision 18100
Added by Go MAEDA 20 days ago

Merged r18098 and r18099 from trunk to 4.0-stable (#31275).

History

#1 Updated by Go MAEDA 21 days ago

  • Category changed from Issues to Attachments
  • Status changed from New to Confirmed

Confirmed that the problem is reproducible in the trunk. No problem with 3.4.

Comparing HTTP headers in Redmine 3.4 and the trunk, I found that the header in the trunk has "Content-Type: text/html; charset=utf-8". This may be the cause.

[3.4-stable]

HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Etag: "c8c16845c9c26151a57d12ea12c26839" 
Content-Disposition: attachment; filename="test.indd" 
Content-Transfer-Encoding: binary
Content-Type:
Cache-Control: private
X-Request-Id: 903252e3-f983-4d73-84f2-b5046dd052ec
X-Runtime: 0.039056
Server: WEBrick/1.3.1 (Ruby/2.2.10/2018-03-28)
Date: Mon, 29 Apr 2019 13:35:02 GMT
Connection: close

[trunk]

HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: strict-origin-when-cross-origin
ETag: W/"c8c16845c9c26151a57d12ea12c26839" 
Content-Type: text/html; charset=utf-8
Content-Disposition: attachment; filename="test.indd" 
Content-Transfer-Encoding: binary
Cache-Control: private
X-Request-Id: 5eb10b0d-88df-47f4-9d20-4cd473d9c64e
X-Runtime: 0.029546
Date: Mon, 29 Apr 2019 13:35:41 GMT
Connection: close

#2 Updated by Go MAEDA 21 days ago

  • Target version set to 4.0.4

The following patch fixes the problem.

Index: app/controllers/attachments_controller.rb
===================================================================
--- app/controllers/attachments_controller.rb    (リビジョン 18097)
+++ app/controllers/attachments_controller.rb    (作業コピー)
@@ -239,7 +239,9 @@
   def detect_content_type(attachment)
     content_type = attachment.content_type
     if content_type.blank? || content_type == "application/octet-stream" 
-      content_type = Redmine::MimeType.of(attachment.filename)
+      content_type =
+        Redmine::MimeType.of(attachment.filename) ||
+        "application/octet-stream" 
     end
     content_type.to_s
   end

#3 Updated by Christian Felix 21 days ago

Thank you for testing and providing a fix for this! Looking forward to the release of 4.0.4

#4 Updated by Go MAEDA 20 days ago

  • Subject changed from Downloading attachment from Redmine with Safari, always adds .html to the file to Safari adds .html extension when downloading files of unknown type
  • Status changed from Confirmed to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix. Thank you for reporting this issue.

#5 Updated by Go MAEDA 20 days ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF