Skip to content

Commit

Permalink
fix leak by converting URL to string
Browse files Browse the repository at this point in the history
  • Loading branch information
agroszer committed Jul 6, 2016
1 parent 37e3820 commit 860294c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/zope/error/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def raising(self, info, request=None):
# TODO: Temporary fix, which Steve should undo. URL is
# just too HTTPRequest-specific.
if hasattr(request, 'URL'):
url = request.URL
url = str(request.URL)
username = self._getUsername(request)
req_html = self._getRequestAsHTML(request)

Expand Down
31 changes: 30 additions & 1 deletion src/zope/error/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from zope.testing import cleanup

from zope.error.error import ErrorReportingUtility, getFormattedException
from zope.error._compat import _u_type, PYTHON2
from zope.error._compat import _u_type, PYTHON2, _basestring

if PYTHON2:
from cStringIO import StringIO
Expand Down Expand Up @@ -56,6 +56,20 @@ def setPrincipal(self, principal):
def items(self):
return []

def getURL(self):
return self._environ['PATH_INFO']


class URLGetter(object):

__slots__ = "__request"

def __init__(self, request):
self.__request = request

def __str__(self):
return self.__request.getURL()


class ErrorReportingUtilityTests(cleanup.CleanUp, unittest.TestCase):

Expand Down Expand Up @@ -119,6 +133,21 @@ class PrincipalStub(object):
username = getErrLog[0]['username']
self.assertEqual(username, u'unauthenticated, \u0441, \u0441, \u0441')

def test_ErrorLog_url(self):
# We want a string for the URL in the error log, nothing else
request = TestRequest(environ={'PATH_INFO': '/foobar'})
# set request.URL as zope.publisher would
request.URL = URLGetter(request)

errUtility = ErrorReportingUtility()
exc_info = getAnErrorInfo(u"Error")
errUtility.raising(exc_info, request=request)
getErrLog = errUtility.getLogEntries()
self.assertEqual(1, len(getErrLog))

url = getErrLog[0]['url']
self.assertTrue(isinstance(url, _basestring))

def test_ErrorLog_nonascii(self):
# Emulate a unicode url, it gets encoded to utf-8 before it's passed
# to the request. Also add some unicode field to the request's
Expand Down

0 comments on commit 860294c

Please sign in to comment.