Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement fnmatch style pattern matching of mimetypes

  • Loading branch information...
commit 6bd19dfdd8ff9fa9addb1d0c44ed6d8bdd54a3d0 1 parent 7b822d9
Dylan Jay authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/plone/app/blob/content.py
View
14 src/plone/app/blob/content.py
@@ -12,6 +12,7 @@
from zope.component import getUtility
from plone.app.content.interfaces import ISiteContentSettings
from plone.registry.interfaces import IRegistry
+from fnmatch import fnmatch
try:
from Products.LinguaPlone.public import registerType
@@ -98,15 +99,20 @@ def index_html(self, REQUEST, RESPONSE):
if IATBlobImage.providedBy(self):
return field.index_html(self, REQUEST, RESPONSE)
elif policySettings.file_mimetype_behaviour is not None:
- behaviour = policySettings.file_mimetype_behaviour.get(mimetype, None)
- if behaviour is None:
- behaviour = policySettings.file_mimetype_behaviour('','attachment')
- if behaviour == 'view':
+ matches = [(pattern, behaviour) for pattern, behaviour in policySettings.file_mimetype_behaviour.items() \
+ if fnmatch(mimetype, pattern)]
+ # pick the longest pattern that matches ie between */* and application/* the latter will win
+ matches.sort(key=lambda kv: len(kv[0]))
+ behaviour = matches[-1][1] if matches else None
+ if behaviour == 'view' and self.getLayout():
return self.restrictedTraverse(self.getLayout())()
elif behaviour == 'inline':
return field.index_html(self, REQUEST, RESPONSE)
elif behaviour == 'attachment':
return field.download(self, REQUEST, RESPONSE)
+ else:
+ return field.download(self, REQUEST, RESPONSE)
+
elif mimetype in ATFile.inlineMimetypes:
return field.index_html(self, REQUEST, RESPONSE)
else:

1 comment on commit 6bd19df

@mister-roboto

Testing:

Please sign in to comment.
Something went wrong with that request. Please try again.