correctly forbid empty Python expression (#24670)

This commit is contained in:
Thomas NOËL 2018-06-21 00:28:42 +02:00
parent 320dee2376
commit 486225c4b2
2 changed files with 17 additions and 2 deletions

View File

@ -502,7 +502,22 @@ def test_computed_expression_widget():
assert not widget.has_error()
widget = ComputedExpressionWidget('test')
mock_form_submission(req, widget, {'test$value_python': '=hello world', 'test$type': ['python']})
mock_form_submission(req, widget, {'test$value_python': 'hello world', 'test$type': ['python']})
assert widget.has_error()
assert widget.get_error().startswith('syntax error')
widget = ComputedExpressionWidget('test')
mock_form_submission(req, widget, {'test$value_python': '=3', 'test$type': ['python']})
assert widget.has_error()
assert widget.get_error().startswith('syntax error')
widget = ComputedExpressionWidget('test')
mock_form_submission(req, widget, {'test$value_python': '', 'test$type': ['python']})
assert widget.has_error()
assert widget.get_error().startswith('syntax error')
widget = ComputedExpressionWidget('test')
mock_form_submission(req, widget, {'test$type': ['python']})
assert widget.has_error()
assert widget.get_error().startswith('syntax error')

View File

@ -2325,7 +2325,7 @@ class ComputedExpressionWidget(CompositeWidget):
if not self.get('type'):
return
value_type = self.get('type')
value_content = self.get('value_%s' % value_type)
value_content = self.get('value_%s' % value_type) or ''
if value_type == 'python':
self.value = '=' + value_content
else: