From 08a80bd2ccc4451a0face05f8a7e1ba1699be1c7 Mon Sep 17 00:00:00 2001 From: LB Date: Thu, 9 Nov 2017 17:07:16 +0700 Subject: [PATCH] add extra template validation before parsing filter specs --- .../wagtailimages/templatetags/wagtailimages_tags.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wagtail/wagtailimages/templatetags/wagtailimages_tags.py b/wagtail/wagtailimages/templatetags/wagtailimages_tags.py index 5807772f6c..2ab47915e7 100644 --- a/wagtail/wagtailimages/templatetags/wagtailimages_tags.py +++ b/wagtail/wagtailimages/templatetags/wagtailimages_tags.py @@ -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: