Skip to content

Commit

Permalink
Merge pr '#139' of amol- into bugfix/lazy_escape
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalresistor committed Jan 29, 2016
2 parents eb688ed + 9636005 commit 947304d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,40 @@ def start_response(status, headers, exc_info=None):
environ['PATH_INFO'] = '/'
assert_equal( m( environ, start_response ), [] )

def test_HTTPFound_unused_environ_variable():
class Crashy(object):
def __str__(self):
raise Exception('I crashed!')

def start_response(status, headers, exc_info=None):
pass
environ = {
'wsgi.url_scheme': 'HTTP',
'SERVER_NAME': 'localhost',
'SERVER_PORT': '80',
'REQUEST_METHOD': 'GET',
'PATH_INFO': '/',
'HTTP_ACCEPT': 'text/html',
'crashy': Crashy()
}

m = _HTTPMove(location='http://www.example.com')
assert_equal( m( environ, start_response ), [
b'<html>\n'
b' <head>\n'
b' <title>None None</title>\n'
b' </head>\n'
b' <body>\n'
b' <h1>None None</h1>\n'
b' The resource has been moved to '
b'<a href="http://www.example.com">'
b'http://www.example.com</a>;\n'
b'you should be redirected automatically.\n'
b'\n\n'
b' </body>\n'
b'</html>' ]
)

def test_HTTPExceptionMiddleware_ok():
def app( environ, start_response ):
return '123'
Expand Down
7 changes: 7 additions & 0 deletions webob/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@
br_re = re.compile(r'<br.*?>', re.I|re.S)
comment_re = re.compile(r'<!--|-->')

def lazify(func):
class _lazyfied(object):
def __init__(self, s): self._s = s
def __str__(self): return func(self._s)
return _lazyfied

def no_escape(value):
if value is None:
return ''
Expand Down Expand Up @@ -274,6 +280,7 @@ def __str__(self):
return self.detail or self.explanation

def _make_body(self, environ, escape):
escape = lazify(escape)
args = {
'explanation': escape(self.explanation),
'detail': escape(self.detail or ''),
Expand Down

0 comments on commit 947304d

Please sign in to comment.