0001-handle-non-ascii-syntax-error-messages-on-conditions.patch
tests/test_api.py | ||
---|---|---|
2092 | 2092 |
assert resp.json['klass'] == 'error' |
2093 | 2093 |
assert 'Python condition cannot contain {{' in resp.json['msg'] |
2094 | 2094 | |
2095 |
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=un+%C3%A9l%C3%A9phant') |
|
2096 |
assert resp.json['klass'] == 'error' |
|
2097 |
assert resp.json['msg'].startswith(u"syntax error: Unused 'éléphant'") |
|
2095 | 2098 |
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=~2') |
2096 | 2099 |
assert resp.json['klass'] == 'error' |
2097 | 2100 |
assert resp.json['msg'].startswith('syntax error') |
wcs/conditions.py | ||
---|---|---|
20 | 20 |
from django.template import Context, Template, TemplateSyntaxError |
21 | 21 | |
22 | 22 |
from qommon import _, get_logger |
23 |
from qommon.misc import site_encode |
|
23 | 24 | |
24 | 25 | |
25 | 26 |
class ValidationError(ValueError): |
... | ... | |
86 | 87 |
try: |
87 | 88 |
compile(self.value, '<string>', 'eval') |
88 | 89 |
except (SyntaxError, TypeError) as e: |
89 |
raise ValidationError(_('syntax error: %s') % e)
|
|
90 |
raise ValidationError(_('syntax error: %s') % site_encode(e))
|
|
90 | 91 | |
91 | 92 |
def validate_django(self): |
92 | 93 |
try: |
93 | 94 |
Template('{%% load %s %%}{%% if %s %%}OK{%% endif %%}' % ( |
94 | 95 |
get_publisher().get_default_templatetags_libraries(), self.value)) |
95 | 96 |
except TemplateSyntaxError as e: |
96 |
raise ValidationError(_('syntax error: %s') % e) |
|
97 |
raise ValidationError(_('syntax error: %s') % site_encode(e)) |
|
97 |
- |