mirror of
https://github.com/django/django.git
synced 2025-04-28 03:04:38 +00:00
Fixed #33653 -- Fixed template crash when calling methods for built-in types without required arguments.
Regression in 09341856ed9008875c1cc883dc0c287670131458.
This commit is contained in:
parent
1a78ef2b85
commit
0dd2920909
@ -913,13 +913,16 @@ class Variable:
|
|||||||
try: # method call (assuming no args required)
|
try: # method call (assuming no args required)
|
||||||
current = current()
|
current = current()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
try:
|
||||||
signature = inspect.signature(current)
|
signature = inspect.signature(current)
|
||||||
|
except ValueError: # No signature found.
|
||||||
|
current = context.template.engine.string_if_invalid
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
signature.bind()
|
signature.bind()
|
||||||
except TypeError: # arguments *were* required
|
except TypeError: # Arguments *were* required.
|
||||||
current = (
|
# Invalid method call.
|
||||||
context.template.engine.string_if_invalid
|
current = context.template.engine.string_if_invalid
|
||||||
) # invalid method call
|
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -183,6 +183,14 @@ class TemplateTestMixin:
|
|||||||
for node in template.nodelist:
|
for node in template.nodelist:
|
||||||
self.assertEqual(node.origin, template.origin)
|
self.assertEqual(node.origin, template.origin)
|
||||||
|
|
||||||
|
def test_render_built_in_type_method(self):
|
||||||
|
"""
|
||||||
|
Templates should not crash when rendering methods for built-in types
|
||||||
|
without required arguments.
|
||||||
|
"""
|
||||||
|
template = self._engine().from_string("{{ description.count }}")
|
||||||
|
self.assertEqual(template.render(Context({"description": "test"})), "")
|
||||||
|
|
||||||
|
|
||||||
class TemplateTests(TemplateTestMixin, SimpleTestCase):
|
class TemplateTests(TemplateTestMixin, SimpleTestCase):
|
||||||
debug_engine = False
|
debug_engine = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user