add extra template validation before parsing filter specs

pull/4023/head
LB 2017-11-09 17:07:16 +07:00 zatwierdzone przez Matt Westcott
rodzic 8f1f7a63d1
commit 08a80bd2cc
1 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -56,6 +56,18 @@ def image(parser, token):
# attributes are not valid when using the 'as img' form of the tag
is_valid = False
if len(filter_specs) == 0:
# there must always be at least one filter spec provided
is_valid = False
if len(bits) == 0:
# no resize rule provided eg. {% image page.image %}
raise template.TemplateSyntaxError(
"no resize rule provided. "
"'image' tag should be of the form {% image self.photo max-320x200 [ custom-attr=\"value\" ... ] %} "
"or {% image self.photo max-320x200 as img %}"
)
if is_valid:
return ImageNode(image_expr, '|'.join(filter_specs), attrs=attrs, output_var_name=output_var_name)
else: