Commit 5c6fd9e9 authored by Nathan Van Gheem's avatar Nathan Van Gheem

merge hotfixes from Products.PloneHotfix20131210

parent 230d8f46
...@@ -838,21 +838,20 @@ class Image(File): ...@@ -838,21 +838,20 @@ class Image(File):
security.declareProtected(View, 'tag') security.declareProtected(View, 'tag')
def tag(self, height=None, width=None, alt=None, def tag(self, height=None, width=None, alt=None,
scale=0, xscale=0, yscale=0, css_class=None, title=None, **args): scale=0, xscale=0, yscale=0, css_class=None, title=None, **args):
""" #Generate an HTML IMG tag for this image, with customization.
Generate an HTML IMG tag for this image, with customization. #Arguments to self.tag() can be any valid attributes of an IMG tag.
Arguments to self.tag() can be any valid attributes of an IMG tag. #'src' will always be an absolute pathname, to prevent redundant
'src' will always be an absolute pathname, to prevent redundant #downloading of images. Defaults are applied intelligently for
downloading of images. Defaults are applied intelligently for #'height', 'width', and 'alt'. If specified, the 'scale', 'xscale',
'height', 'width', and 'alt'. If specified, the 'scale', 'xscale', #and 'yscale' keyword arguments will be used to automatically adjust
and 'yscale' keyword arguments will be used to automatically adjust #the output height and width values of the image tag.
the output height and width values of the image tag.
#Since 'class' is a Python reserved word, it cannot be passed in
Since 'class' is a Python reserved word, it cannot be passed in #directly in keyword arguments which is a problem if you are
directly in keyword arguments which is a problem if you are #trying to use 'tag()' to include a CSS class. The tag() method
trying to use 'tag()' to include a CSS class. The tag() method #will accept a 'css_class' argument that will be converted to
will accept a 'css_class' argument that will be converted to #'class' in the output tag to work around this.
'class' in the output tag to work around this.
"""
if height is None: height=self.height if height is None: height=self.height
if width is None: width=self.width if width is None: width=self.width
......
...@@ -353,8 +353,17 @@ class ImageTests(FileTests): ...@@ -353,8 +353,17 @@ class ImageTests(FileTests):
verifyClass(IWriteLock, Image) verifyClass(IWriteLock, Image)
class ImagePublishTests(Testing.ZopeTestCase.FunctionalTestCase):
def testTagSafe(self):
self.app.manage_addImage("image", "")
res = self.publish("/image/tag?height=0&width=0&css_class=%22%3E%3Cscript%20type%3D%22text%2Fjavascript%22%3Ealert('evil')%3B%3C%2Fscript%3E%3Cdiv%20class%3D%22")
self.assertNotIn('<script type="text/javascript">alert(\'evil\');</script>', res.getBody())
def test_suite(): def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
unittest.makeSuite(FileTests), unittest.makeSuite(FileTests),
unittest.makeSuite(ImageTests), unittest.makeSuite(ImageTests),
unittest.makeSuite(ImagePublishTests)
)) ))
...@@ -266,8 +266,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs): ...@@ -266,8 +266,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
security.declareProtected(ACCESS_CONTENTS_PERM, 'encodeUrl') security.declareProtected(ACCESS_CONTENTS_PERM, 'encodeUrl')
def encodeUrl(self, url, style='querystring', create=1): def encodeUrl(self, url, style='querystring', create=1):
""" See IBrowserIdManager. # See IBrowserIdManager
"""
bid = self.getBrowserId(create) bid = self.getBrowserId(create)
if bid is None: if bid is None:
raise BrowserIdManagerErr('There is no current browser id.') raise BrowserIdManagerErr('There is no current browser id.')
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
Test suite for session id manager. Test suite for session id manager.
""" """
import unittest import unittest
import Testing
class TestBrowserIdManager(unittest.TestCase): class TestBrowserIdManager(unittest.TestCase):
...@@ -642,6 +643,18 @@ class TestBrowserIdManagerTraverser(unittest.TestCase): ...@@ -642,6 +643,18 @@ class TestBrowserIdManagerTraverser(unittest.TestCase):
self.assertEqual(request._script[1], bid) self.assertEqual(request._script[1], bid)
class TestBrowserIdManagerPublish(Testing.ZopeTestCase.FunctionalTestCase):
def test_encodeUrl_safe(self):
from OFS.Application import AppInitializer
init = AppInitializer(self.app)
init.install_browser_id_manager()
res = self.publish(
'/browser_id_manager/encodeUrl?url=%3Chtml%3EEVIL%2Fhtml%3E%3C!--')
self.assertNotIn("<html>EVIL/html>", res.getBody())
class DummyObject: class DummyObject:
def __init__(self, **kw): def __init__(self, **kw):
self.__dict__.update(kw) self.__dict__.update(kw)
...@@ -667,4 +680,5 @@ def test_suite(): ...@@ -667,4 +680,5 @@ def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
unittest.makeSuite(TestBrowserIdManager), unittest.makeSuite(TestBrowserIdManager),
unittest.makeSuite(TestBrowserIdManagerTraverser), unittest.makeSuite(TestBrowserIdManagerTraverser),
unittest.makeSuite(TestBrowserIdManagerPublish),
)) ))
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