From 4e24d6ee17c81f7a426c2aaa22d951b9c9688197 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sun, 2 Jul 2017 11:26:29 +0100 Subject: [PATCH] correct error for badly closed tag --- chevron/tokenizer.py | 6 +++++- test_spec.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/chevron/tokenizer.py b/chevron/tokenizer.py index ea3f6b2..ed5799e 100644 --- a/chevron/tokenizer.py +++ b/chevron/tokenizer.py @@ -79,7 +79,11 @@ def parse_tag(template, l_del, r_del): } # Get the tag - tag, template = template.split(r_del, 1) + try: + tag, template = template.split(r_del, 1) + except ValueError: + raise ChevronError('unclosed tag ' + 'at line {0}'.format(_CURRENT_LINE)) # Find the type meaning of the first character tag_type = tag_types.get(tag[0], 'variable') diff --git a/test_spec.py b/test_spec.py index 4fb5d14..5b34811 100755 --- a/test_spec.py +++ b/test_spec.py @@ -194,6 +194,14 @@ class ExpandedCoverage(unittest.TestCase): self.assertEqual(result, expected) + def test_closing_tag_only(self): + args = { + 'template': '{{ foo } bar', + 'data': {'foo': 'xx'} + } + + self.assertRaises(chevron.ChevronError, chevron.render, **args) + # Run unit tests from command line if __name__ == "__main__": -- 2.47.3