misc: catch OverflowError that can be raised by django template (#41908)

This commit is contained in:
Frédéric Péters 2020-04-21 11:00:25 +02:00
parent 064f6bbb68
commit db7bc6dd17
2 changed files with 4 additions and 1 deletions

View File

@ -2854,6 +2854,9 @@ def test_validate_condition(pub):
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=~2')
assert resp.json['klass'] == 'error'
assert resp.json['msg'].startswith('syntax error')
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=%22...%22+inf') # "..." + inf
assert resp.json['klass'] == 'error'
assert resp.json['msg'].startswith('syntax error')
resp = get_app(pub).get('/api/validate-condition?type=unknown&value_unknown=2')
assert resp.json['klass'] == 'error'

View File

@ -92,5 +92,5 @@ class Condition(object):
def validate_django(self):
try:
Template('{%% if %s %%}OK{%% endif %%}' % self.value)
except TemplateSyntaxError as e:
except (TemplateSyntaxError, OverflowError) as e:
raise ValidationError(_('syntax error: %s') % force_str(force_text(e)))