From 602ebc21bda3b4fb9424e76226db9d16f40de0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 19 Sep 2016 08:55:22 +0200 Subject: [PATCH 1/2] misc: validate [is varname ...] syntax (#13185) --- tests/test_ezt.py | 12 +++++++++++- wcs/qommon/ezt.py | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_ezt.py b/tests/test_ezt.py index de39c0e..87a62f3 100644 --- a/tests/test_ezt.py +++ b/tests/test_ezt.py @@ -3,7 +3,8 @@ import os from StringIO import StringIO from quixote import cleanup -from wcs.qommon.ezt import Template, UnclosedBlocksError, UnmatchedEndError, UnmatchedElseError +from wcs.qommon.ezt import (Template, UnclosedBlocksError, UnmatchedEndError, + UnmatchedElseError, ArgCountSyntaxError) from wcs.scripts import ScriptsSubstitutionProxy from utilities import get_app, create_temporary_pub @@ -109,6 +110,15 @@ def test_unmatched_else(): except UnmatchedElseError as e: assert e.column == 3 and e.line == 0 +def test_missing_is_arg(): + template = Template() + with pytest.raises(ArgCountSyntaxError): + template.parse('[is foobar][end]') + try: + template.parse('\ntest [is foobar][end]') + except ArgCountSyntaxError as e: + assert e.column == 5 and e.line == 1 + def test_array_index(): template = Template() template.parse('

[foo.0]

') diff --git a/wcs/qommon/ezt.py b/wcs/qommon/ezt.py index 6e0633c..a223362 100644 --- a/wcs/qommon/ezt.py +++ b/wcs/qommon/ezt.py @@ -409,6 +409,8 @@ class Template: # handle arg2 for the 'is' command if cmd == 'is': + if len(args) != 3: + raise ArgCountSyntaxError(str(args[1:]), line, column) args[2] = _prepare_ref(args[2], for_names, file_args) elif cmd == 'for': for_names.append(args[1][0]) # append the refname -- 2.9.3