From 79ce25d44a2d055a4f98c1b0cbf1d67140f0ba62 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Wed, 19 Nov 2014 15:29:28 +0530 Subject: [PATCH] Validate jinja2 syntax before saving print format --- frappe/core/doctype/print_format/print_format.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frappe/core/doctype/print_format/print_format.py b/frappe/core/doctype/print_format/print_format.py index a770062147..4d414c50e5 100644 --- a/frappe/core/doctype/print_format/print_format.py +++ b/frappe/core/doctype/print_format/print_format.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import frappe import frappe.utils +from jinja2 import TemplateSyntaxError from frappe.model.document import Document @@ -16,6 +17,12 @@ class PrintFormat(Document): self.old_doc_type = frappe.db.get_value('Print Format', self.name, 'doc_type') + jenv = frappe.get_jenv() + try: + jenv.from_string(self.html) + except TemplateSyntaxError: + frappe.throw(frappe._("Syntax error in Jinja template")) + def on_update(self): if hasattr(self, 'old_doc_type') and self.old_doc_type: frappe.clear_cache(doctype=self.old_doc_type)