Skip to content

Commit

Permalink
- Don't call HTTPExceptions that are looked up in TemplateDicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed May 13, 2019
1 parent bc6f0ef commit 9e57b25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog
3.1 (unreleased)
----------------

- Nothing changed yet.
Bug fixes
+++++++++

- Don't call HTTPExceptions that are looked up in TemplateDicts


3.0 (2019-05-09)
Expand Down
3 changes: 2 additions & 1 deletion src/DocumentTemplate/_DocumentTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@

from Acquisition import aq_base
from ExtensionClass import Base
from zExceptions import HTTPException

from DocumentTemplate.html_quote import html_quote
from DocumentTemplate.ustr import ustr
Expand Down Expand Up @@ -393,7 +394,7 @@ def getitem(self, key, call=0):
return e.__render_with_namespace__(self)

base = aq_base(e)
if safe_callable(base):
if safe_callable(base) and not isinstance(base, HTTPException):
if getattr(base, 'isDocTemp', False):
return e(None, self)
return e()
Expand Down
13 changes: 13 additions & 0 deletions src/DocumentTemplate/tests/test_templatedict.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ def test_callable_namespace(self):
td._push({'one': DummyNamespace('one')})
self.assertEqual(td['one'], ('namespace', 'one', (td, )))

def test_callable_httpexception(self):
# Subclasses of zException.HTTPException are callable but should
# not be called during lookup in the template dict.
from zExceptions import NotFound
from zExceptions import Unauthorized

notfound = NotFound('ouch')
unauth = Unauthorized('argh')
td = TemplateDict()
td._push({'one': unauth, 'two': notfound})
self.assertEqual(td['one'], unauth)
self.assertEqual(td['two'], notfound)


class TestRestrictedTemplateDict(unittest.TestCase):
# Based on tests for Products.PageTemplates.ZRPythonExpr.
Expand Down

0 comments on commit 9e57b25

Please sign in to comment.