#26478: Template Context should validate names
-------------------------------+----------------------
Reporter: steveire | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords: template
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+----------------------
The 'for' tag does not validate names of unpacked variables, allowing
things like
`{% for k|upper, "v" in mapping.items %}`
without throwing an error. Such 'variables' are not useful within the
`for` block.
{{{#!python
#!/usr/bin/env python
from django.template import Template, Context
from django.template.engine import Engine
e = Engine()
c = Context()
c["m"] = {"one": "1", "two": "2"}
t = e.from_string('{% for k|upper, v in m.items %}{{ k|upper }} : {{ v
}}\n{% endfor %}')
print t.render(c)
# : 2
# : 1
t = e.from_string('{% for "k", v in m.items %}{{ "k" }} : {{ v }}\n{%
endfor %}')
print t.render(c)
# k : 2
# k : 1
}}}
The for tag should error on an attempt to unpack to variables which
contain FILTER_SEPARATOR, double-quoted string or single-quoted string.
The underlying issue is that `Context` does not validate keys it is given,
so the `cycle` tag also has this issue in the form of `{% cycle 'a' 'b'
'c' as "letter" %}`, as does `widthratio` and any other tag which has an
'as' form.
--
Ticket URL: <https://code.djangoproject.com/ticket/26478>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.b5100522aedf23be1132a921e4a562ee%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.