Opened 95 minutes ago
Last modified 83 minutes ago
#36998 new Bug
firstof tag doesn't require an argument when used with as var
| Reported by: | Lily | Owned by: | |
|---|---|---|---|
| Component: | Template system | Version: | 6.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Pravin | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
The {% firstof %} template tag raises a TemplateSyntaxError("'firstof' statement requires at least one argument") when called with no arguments.
However, when called with exactly two arguments that match the variable capturing syntax (e.g. {% firstof as foo %}) no error is raised and the FirstOfNode is returned with an empty vars list (and an asvar of e.g. foo). It would be consistent to raise a TemplateSyntaxError("'firstof' statement requires at least one argument before 'as'") here.
This was discovered when re-implementing `firstof` in django-rusty-templates.