mirror of
https://github.com/django-components/django-components.git
synced 2025-10-17 09:17:10 +00:00
* Add regression test for recursion bug, #68 * Only allow slots to access slot nodelists provided to their immediate parent component to prevent infinite recursions. * Fix import ordering bug in test * Add slot.super to docs Remove unused imports * Bump version Co-authored-by: rbeard0330 <@dul2k3BKW6m>
This commit is contained in:
parent
7f4661922a
commit
e3c9ac76ce
6 changed files with 74 additions and 13 deletions
|
@ -215,3 +215,45 @@ class ComponentIsolationTests(SimpleTestCase):
|
|||
</custom-template>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
class RecursiveSlotNameTest(SimpleTestCase):
|
||||
def setUp(self):
|
||||
@component.register('outer')
|
||||
class OuterComponent(component.Component):
|
||||
def template(self, context):
|
||||
return "slotted_template.html"
|
||||
|
||||
@component.register('inner')
|
||||
class InnerComponent(component.Component):
|
||||
def template(self, context):
|
||||
return "slotted_template.html"
|
||||
|
||||
def test_no_infinite_recursion_when_slot_name_is_reused(self):
|
||||
template = Template(
|
||||
"""
|
||||
{% load component_tags %}
|
||||
{% component_block "outer" %}
|
||||
{% slot "header" %}
|
||||
{% component_block "inner" %}{% endcomponent_block %}
|
||||
{% endslot %}
|
||||
{% endcomponent_block %}
|
||||
"""
|
||||
)
|
||||
|
||||
self.assertHTMLEqual(
|
||||
template.render(Context({})),
|
||||
"""
|
||||
<custom-template>
|
||||
<header>
|
||||
<custom-template>
|
||||
<header>Default header</header>
|
||||
<main>Default main</main>
|
||||
<footer>Default footer</footer>
|
||||
</custom-template>
|
||||
</header>
|
||||
<main>Default main</main>
|
||||
<footer>Default footer</footer>
|
||||
</custom-template>
|
||||
"""
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue