Commit 1c1dc58e authored by Tres Seaver's avatar Tres Seaver

Forward port better fix and test for LP #491224 from 2.8 branch.

parent ff9c85c8
...@@ -36,7 +36,6 @@ from DocumentTemplate.html_quote import html_quote ...@@ -36,7 +36,6 @@ from DocumentTemplate.html_quote import html_quote
from DocumentTemplate.ustr import ustr from DocumentTemplate.ustr import ustr
from ExtensionClass import Base from ExtensionClass import Base
from webdav.Resource import Resource from webdav.Resource import Resource
from webdav.xmltools import escape as xml_escape
from zExceptions import Redirect from zExceptions import Redirect
from zExceptions.ExceptionFormatter import format_exception from zExceptions.ExceptionFormatter import format_exception
from zope.interface import implements from zope.interface import implements
...@@ -234,7 +233,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -234,7 +233,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
exc_info=True exc_info=True
) )
try: try:
strv = str(error_value) strv = repr(error_value) # quotes tainted strings
except: except:
strv = ('<unprintable %s object>' % strv = ('<unprintable %s object>' %
str(type(error_value).__name__)) str(type(error_value).__name__))
...@@ -244,7 +243,6 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -244,7 +243,6 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
"event log for full details: %s)")%( "event log for full details: %s)")%(
html_quote(sys.exc_info()[1]), html_quote(sys.exc_info()[1]),
)) ))
v = xml_escape(v)
raise error_type, v, tb raise error_type, v, tb
finally: finally:
if hasattr(self, '_v_eek'): del self._v_eek if hasattr(self, '_v_eek'): del self._v_eek
......
...@@ -3,14 +3,60 @@ import unittest ...@@ -3,14 +3,60 @@ import unittest
class TestItem(unittest.TestCase): class TestItem(unittest.TestCase):
def test_z3interfaces(self): def _getTargetClass(self):
from OFS.SimpleItem import Item
return Item
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
def test_conforms_to_IItem(self):
from OFS.interfaces import IItem from OFS.interfaces import IItem
from zope.interface.verify import verifyClass
verifyClass(IItem, self._getTargetClass())
def test_conforms_to_IManageable(self):
from OFS.interfaces import IManageable from OFS.interfaces import IManageable
from OFS.SimpleItem import Item
from zope.interface.verify import verifyClass from zope.interface.verify import verifyClass
verifyClass(IItem, Item) verifyClass(IManageable, self._getTargetClass())
verifyClass(IManageable, Item)
def test_raise_StandardErrorMessage_str_errorValue(self):
item = self._makeOne()
def _raise_during_standard_error_message(*args, **kw):
raise ZeroDivisionError('testing')
item.standard_error_message = _raise_during_standard_error_message
try:
item.raise_standardErrorMessage(
error_type=OverflowError,
error_value='simple',
REQUEST={'dummy': ''},
)
except:
import sys
self.assertEqual(sys.exc_info()[0], 'OverflowError')
value = sys.exc_info()[1]
self.failUnless(value.startswith("'simple'"))
self.failUnless('full details: testing' in value)
def test_raise_StandardErrorMessage_TaintedString_errorValue(self):
from ZPublisher.TaintedString import TaintedString
item = self._makeOne()
def _raise_during_standard_error_message(*args, **kw):
raise ZeroDivisionError('testing')
item.standard_error_message = _raise_during_standard_error_message
try:
item.raise_standardErrorMessage(
error_type=OverflowError,
error_value=TaintedString('<simple>'),
REQUEST={'dummy': ''},
)
except:
import sys
self.assertEqual(sys.exc_info()[0], 'OverflowError')
value = sys.exc_info()[1]
self.failIf('<' in value)
class TestItem_w__name__(unittest.TestCase): class TestItem_w__name__(unittest.TestCase):
......
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