Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested repeat variables with same name handled improperly #311

Closed
d-maurer opened this issue May 27, 2020 · 1 comment
Closed

Nested repeat variables with same name handled improperly #311

d-maurer opened this issue May 27, 2020 · 1 comment
Labels
core duplicate Duplicate issue

Comments

@d-maurer
Copy link

Playing around with a proper error representation for the RepeatDict, I got the impression that nested repeat variables using the same name could be improperly handled.

The following script demonstrates that this is really the case:

>>> from chameleon.zpt.template import PageTemplate
>>> t = PageTemplate("""\
... <div tal:repeat="i (1, 2, 3)">
...   <span tal:content="'%s(%s)' % (i, repeat['i'].index)" />: <span tal:repeat="i (1, 2, 3)" tal:content="i" /></div>
... """)
>>> print (t())
<div>
  <span>1(0)</span>: <span>1</span>
  <span>2</span>
  <span>3</span></div>
<div>
  <span>2(2)</span>: <span>1</span>
  <span>2</span>
  <span>3</span></div>
<div>
  <span>3(2)</span>: <span>1</span>
  <span>2</span>
  <span>3</span></div>

As you see, the inner (i) loop has corrupted the outer repeat item (which is clear as there is a single dict).

Due to macros, a template writer may not know which nested repeat names are used. It may therefore be difficult to avoid the problem.

zope.pagetemplate uses a MultiMapping (essentially a stack of dicts) to avoid this problem. When a scope is entered, a new empty dict is pushed; when a scope is exited, the dict is popped.

@dataflake
Copy link
Collaborator

This is a duplicate of #177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core duplicate Duplicate issue
Projects
None yet
Development

No branches or pull requests

3 participants