[Checkins] SVN: zope.error/trunk/ Don't HTML-escape HTML tracebacks twice.
Marius Gedminas
cvs-admin at zope.org
Mon Dec 10 17:18:17 UTC 2012
Log message for revision 128556:
Don't HTML-escape HTML tracebacks twice.
Changed:
U zope.error/trunk/CHANGES.txt
U zope.error/trunk/src/zope/error/error.py
U zope.error/trunk/src/zope/error/tests.py
-=-
Modified: zope.error/trunk/CHANGES.txt
===================================================================
--- zope.error/trunk/CHANGES.txt 2012-12-10 17:15:14 UTC (rev 128555)
+++ zope.error/trunk/CHANGES.txt 2012-12-10 17:18:17 UTC (rev 128556)
@@ -12,7 +12,9 @@
- Sort request items for presentation in the error reporting utility.
+- Don't HTML-escape HTML tracebacks twice.
+
3.7.4 (2012-02-01)
------------------
Modified: zope.error/trunk/src/zope/error/error.py
===================================================================
--- zope.error/trunk/src/zope/error/error.py 2012-12-10 17:15:14 UTC (rev 128555)
+++ zope.error/trunk/src/zope/error/error.py 2012-12-10 17:18:17 UTC (rev 128556)
@@ -59,7 +59,7 @@
codecs.register_error("zope.error.printedreplace", printedreplace)
-def getPrintable(value):
+def getPrintable(value, as_html=False):
if not isinstance(value, unicode):
if not isinstance(value, str):
# A call to str(obj) could raise anything at all.
@@ -74,12 +74,15 @@
return u"<unprintable %s object>" % (
xml_escape(type(value).__name__))
value = unicode(value, errors="zope.error.printedreplace")
- return xml_escape(value)
+ if as_html:
+ return value
+ else:
+ return xml_escape(value)
def getFormattedException(info, as_html=False):
lines = []
for line in format_exception(as_html=as_html, *info):
- line = getPrintable(line)
+ line = getPrintable(line, as_html=as_html)
if not line.endswith("\n"):
if not as_html:
line += "\n"
Modified: zope.error/trunk/src/zope/error/tests.py
===================================================================
--- zope.error/trunk/src/zope/error/tests.py 2012-12-10 17:15:14 UTC (rev 128555)
+++ zope.error/trunk/src/zope/error/tests.py 2012-12-10 17:18:17 UTC (rev 128556)
@@ -15,6 +15,7 @@
"""
import sys
import unittest
+import doctest
from zope.exceptions.exceptionformatter import format_exception
from zope.testing import cleanup
@@ -178,3 +179,45 @@
NonStr.__name__ = '<script>'
self.assertEqual(u'<unprintable <script> object>',
self.getPrintable(NonStr()))
+
+
+def doctest_getFormattedException():
+ """Test for getFormattedException
+
+ >>> try:
+ ... raise Exception('<boom>')
+ ... except:
+ ... print getFormattedException(sys.exc_info()),
+ Traceback (most recent call last):
+ Module zope.error.tests, line 2, in <module>
+ raise Exception('<boom>')
+ Exception: <boom>
+
+ """
+
+
+def doctest_getFormattedException_as_html():
+ """Test for getFormattedException
+
+ >>> try:
+ ... raise Exception('<boom>')
+ ... except:
+ ... print getFormattedException(sys.exc_info(), as_html=True),
+ <p>Traceback (most recent call last):</p>
+ <ul>
+ <li> Module zope.error.tests, line 2, in <module><br />
+ raise Exception('<boom>')</li>
+ </ul><p>Exception: <boom><br />
+ </p><br />
+
+ If this fails because you get '<br />' instead of '<br />' at the
+ end of the penultimate line, you need zope.exceptions 4.0.3 with the bugfix
+ for that.
+ """
+
+
+def test_suite():
+ return unittest.TestSuite([
+ unittest.defaultTestLoader.loadTestsFromName(__name__),
+ doctest.DocTestSuite(optionflags=doctest.NORMALIZE_WHITESPACE),
+ ])
More information about the checkins
mailing list