Handle UnicodeEncodeError in validate_integer
validate_integer can be potentially passed user supplied data which causes a UnicodeEncodeError exception during validation rather than just ValueError. This change handles the UnicodeEncode exception so validate_integer treats it as invalid input. Change-Id: I5177789299b02448ed53e1b7fc23ccdaee1b70d3 Partial-Bug: 1243037
This commit is contained in:
@@ -738,6 +738,10 @@ class ValidateIntegerTestCase(test.NoDBTestCase):
|
||||
utils.validate_integer,
|
||||
55, "doing 55 in a 54",
|
||||
max_value=54)
|
||||
self.assertRaises(exception.InvalidInput,
|
||||
utils.validate_integer,
|
||||
unichr(129), "UnicodeError",
|
||||
max_value=1000)
|
||||
|
||||
|
||||
class ValidateNeutronConfiguration(test.NoDBTestCase):
|
||||
|
||||
@@ -968,7 +968,7 @@ def validate_integer(value, name, min_value=None, max_value=None):
|
||||
"""Make sure that value is a valid integer, potentially within range."""
|
||||
try:
|
||||
value = int(str(value))
|
||||
except ValueError:
|
||||
except (ValueError, UnicodeEncodeError):
|
||||
msg = _('%(value_name)s must be an integer')
|
||||
raise exception.InvalidInput(reason=(
|
||||
msg % {'value_name': name}))
|
||||
|
||||
Reference in New Issue
Block a user