osx_defaults: fix handling negative integers (#676)

* osx_defaults: fix handling negative integers

* add changelog fragment
This commit is contained in:
Andrew Klychkov 2020-07-21 17:12:21 +03:00 committed by GitHub
commit c207b7298c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -169,6 +169,14 @@ class OSXDefaults(object):
# /init --------------------------------------------------------------- }}}
# tools --------------------------------------------------------------- {{{
@staticmethod
def is_int(value):
as_str = str(value)
if (as_str.startswith("-")):
return as_str[1:].isdigit()
else:
return as_str.isdigit()
@staticmethod
def _convert_type(data_type, value):
""" Converts value to given type """
@ -190,7 +198,7 @@ class OSXDefaults(object):
"Invalid date value: {0}. Required format yyy-mm-dd hh:mm:ss.".format(repr(value))
)
elif data_type in ["int", "integer"]:
if not str(value).isdigit():
if not OSXDefaults.is_int(value):
raise OSXDefaultsException("Invalid integer value: {0}".format(repr(value)))
return int(value)
elif data_type == "float":