handle non-ascii syntax error messages on conditions (#25954)
This commit is contained in:
parent
fe84f8410c
commit
c29d4735ca
|
@ -2092,6 +2092,9 @@ def test_validate_condition(pub):
|
|||
assert resp.json['klass'] == 'error'
|
||||
assert 'Python condition cannot contain {{' in resp.json['msg']
|
||||
|
||||
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=un+%C3%A9l%C3%A9phant')
|
||||
assert resp.json['klass'] == 'error'
|
||||
assert resp.json['msg'].startswith(u"syntax error: Unused 'éléphant'")
|
||||
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')
|
||||
|
|
|
@ -20,6 +20,7 @@ from quixote import get_publisher
|
|||
from django.template import Context, Template, TemplateSyntaxError
|
||||
|
||||
from qommon import _, get_logger
|
||||
from qommon.misc import site_encode
|
||||
|
||||
|
||||
class ValidationError(ValueError):
|
||||
|
@ -86,11 +87,11 @@ class Condition(object):
|
|||
try:
|
||||
compile(self.value, '<string>', 'eval')
|
||||
except (SyntaxError, TypeError) as e:
|
||||
raise ValidationError(_('syntax error: %s') % e)
|
||||
raise ValidationError(_('syntax error: %s') % site_encode(e))
|
||||
|
||||
def validate_django(self):
|
||||
try:
|
||||
Template('{%% load %s %%}{%% if %s %%}OK{%% endif %%}' % (
|
||||
get_publisher().get_default_templatetags_libraries(), self.value))
|
||||
except TemplateSyntaxError as e:
|
||||
raise ValidationError(_('syntax error: %s') % e)
|
||||
raise ValidationError(_('syntax error: %s') % site_encode(e))
|
||||
|
|
Loading…
Reference in New Issue