Commit bab42871 authored by Jérome Perrin's avatar Jérome Perrin

CSV problems revealed by new cloudooo

New cloudooo uses text/csv as mimetype for CSV, which is correct, but this revealed issues in ERP5:
 - ERP5 did not detect text/csv for csv extensions
 - downloading a file with content type text/csv caused an error

See merge request !1859
parents 3e751636 5ea313bb
Pipeline #31984 failed with stage
in 0 seconds
......@@ -691,6 +691,56 @@ class TestDocument(TestDocumentMixin):
'attachment; filename="PDF.pdf"; filename*=UTF-8\'\'PDF%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.pdf',
)
def test_download_content_type_by_mimetype_registry_extension(self):
content_type = 'application/andrew-inset'
data = b"data"
mime_type_entry, = self.portal.mimetypes_registry.lookup(content_type)
self.assertTrue(mime_type_entry.extensions)
doc = self.portal.document_module.newContent(
portal_type='File',
content_type=content_type,
data=data,
)
doc.publish()
self.tic()
response = self.publish('%s?format=' % doc.getPath())
self.assertEqual(response.getBody(), data)
self.assertEqual(response.getHeader('Content-Type'), content_type)
def test_download_content_type_by_mimetype_registry_glob(self):
content_type = 'application/x-compressed-tar'
data = (
b"\x1f\x8b\x08\x08e\x8a\x89e\x00\x03empty.tar\x00\xed\xc1\x01\r\x00\x00\x00\xc2\xa0"
b"\xf7Om\x0e7\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x807\x03\x9a\xde\x1d'\x00(\x00\x00")
mime_type_entry, = self.portal.mimetypes_registry.lookup(content_type)
self.assertFalse(mime_type_entry.extensions)
self.assertTrue(mime_type_entry.globs)
doc = self.portal.document_module.newContent(
portal_type='File',
content_type=content_type,
data=data,
)
doc.publish()
self.tic()
response = self.publish('%s?format=' % doc.getPath())
self.assertEqual(response.getBody(), data)
self.assertEqual(response.getHeader('Content-Type'), content_type)
def test_csv(self):
doc = self.portal.document_module.newContent(
portal_type='Spreadsheet',
file=makeFileUpload('simple.csv'),
)
self.assertEqual(doc.getContentType(), 'text/csv')
doc.publish()
self.tic()
response = self.publish('%s?format=' % doc.getPath())
self.assertEqual(response.getBody(), makeFileUpload('simple.csv').read())
self.assertEqual(response.getHeader('Content-Type'), 'text/csv; charset=utf-8')
self.assertEqual(response.getHeader('Content-Disposition'), 'attachment; filename="simple.csv"')
def test_05_getCreationDate(self):
"""
Check getCreationDate on all document types.
......
......@@ -140,7 +140,7 @@ class DownloadableMixin:
output_format = mimetype_object.extensions[0]
break
elif mimetype_object.globs:
output_format = mimetype_object.globs.strip('*.')
output_format = mimetype_object.globs[0].strip('*.')
break
if output_format is None:
output_format = format
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -549,7 +549,7 @@ class OOoTemplate(ZopePageTemplate):
extension = mimetype_object.extensions[0]
break
elif mimetype_object.globs:
extension = mimetype_object.globs.strip('*.')
extension = mimetype_object.globs[0].strip('*.')
break
if extension:
filename = '%s.%s' % (self._getFileName(), extension)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment