Fix infinite recursion bug (fixes #68) (#74)

* 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:
rbeard0330 2021-07-06 11:56:49 -04:00 committed by GitHub
parent 7f4661922a
commit e3c9ac76ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 13 deletions

View file

@ -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>
"""
)