Commit aff30449 authored by Rafael Monnerat's avatar Rafael Monnerat

Fix convetsion and content type when convert to svg

In order to fix content type it was Introduced a small
Monkey-Patch for zope.contenttype in order to detect
image/svg+xml content types. This is broken even in newer
versions and this monkey patch is foward compatible.

Update Document and tests to permit conversions to SVG, this
prevents get Unauthorized when use ?format=svg.
parent 72af82b1
......@@ -69,8 +69,8 @@ FIXED_PROPERTY_IDS = ('id', 'uid', 'rid', 'sid')
VALID_TEXT_FORMAT_LIST = ('text', 'txt', 'html', 'base_html',
'stripped-html')
VALID_IMAGE_FORMAT_LIST = ('jpg', 'jpeg', 'png', 'gif', 'pnm', 'ppm', 'tiff')
VALID_TRANSPARENT_IMAGE_FORMAT_LIST = ('png', 'gif', 'tiff')
VALID_IMAGE_FORMAT_LIST = ('jpg', 'jpeg', 'png', 'gif', 'pnm', 'ppm', 'tiff', 'svg')
VALID_TRANSPARENT_IMAGE_FORMAT_LIST = ('png', 'gif', 'tiff', 'svg')
DEFAULT_DISPLAY_ID_LIST = ('nano', 'micro', 'thumbnail',
'xsmall', 'small', 'medium',
......
......@@ -60,7 +60,6 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
manager_password = 'zope'
website_id = 'test'
def getTitle(self):
return "ERP5WebWithDms"
......@@ -713,6 +712,11 @@ return True
image_reference + '?format=jpg', credential)
self.assertEquals(response.getHeader('content-type'), 'image/jpeg')
# testing Image conversions, svg
response = self.publish(website.absolute_url_path() + '/' +\
image_reference + '?format=svg', credential)
self.assertEquals(response.getHeader('content-type'), 'image/svg+xml')
# testing Image conversions, resizing
response = self.publish(website.absolute_url_path() + '/' +\
image_reference + '?display=large', credential)
......
......@@ -71,6 +71,7 @@ from Products.ERP5Type.patches import OFSHistory
from Products.ERP5Type.patches import OFSItem
from Products.ERP5Type.patches import ExternalMethod
from Products.ERP5Type.patches import User
from Products.ERP5Type.patches import zopecontenttype
# These symbols are required for backward compatibility
from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager
......
# Monkey Patch the zope.contenttype to be able to detect svg image format.
try:
import zope.contenttype
original_text_type = zope.contenttype.text_type
def svg_fix_text_type(s):
s = s.strip()
if '<html>' not in s and "<svg" in s:
return 'image/svg+xml'
# If it is not an svg, just try original behaviour.
# This preserve the further improvements on zope.contenttype
# and preserve the fix.
return original_text_type(s)
# Overwrite original method with the SVG detection fix.
zope.contenttype.text_type = svg_fix_text_type
except ImportError:
print "Skip to patch zope.contenttype, because it is not present."
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