misc: don't break on incomplete ezt "for" expression (#20721)

This commit is contained in:
Frédéric Péters 2021-10-24 15:24:56 +02:00
parent 502643aa2e
commit 74f6f5a014
2 changed files with 8 additions and 0 deletions

View File

@ -100,6 +100,12 @@ def test_validate_expression(pub):
resp = get_app(pub).get('/api/validate-expression?expression={{hello+%C3%A9l%C3%A9phant}}')
assert resp.json['klass'] == 'error'
assert resp.json['msg'].startswith('syntax error in Django template: Could not parse the remainder')
# broken ezt
resp = get_app(pub).get('/api/validate-expression?expression=[for]')
assert resp.json == {
'klass': 'error',
'msg': 'syntax error in ezt template: wrong number of arguments at line 1 and column 1',
}
def test_validate_condition(pub):

View File

@ -413,6 +413,8 @@ class Template:
raise ArgCountSyntaxError(str(args[1:]), line, column)
# this assumes arg1 is always a ref unless cmd is 'define'
if cmd != 'define':
if len(args) < 2:
raise ArgCountSyntaxError(str(args), line, column)
args[1] = _prepare_ref(args[1], for_names, file_args)
# handle arg2 for the 'is' command