mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
osx_defaults: fix handling negative integers (#676)
* osx_defaults: fix handling negative integers * add changelog fragment
This commit is contained in:
parent
d7aabcceed
commit
c207b7298c
3 changed files with 12 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- osx_defaults - fix handling negative integers (https://github.com/ansible-collections/community.general/issues/134).
|
|
@ -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":
|
||||
|
|
|
@ -177,6 +177,7 @@
|
|||
with_items: &data_type
|
||||
- { type: 'int', value: 1, key: 'sample_int'}
|
||||
- { type: 'integer', value: 1, key: 'sample_int_2'}
|
||||
- { type: 'integer', value: -1, key: 'negative_int'}
|
||||
- { type: 'bool', value: True, key: 'sample_bool'}
|
||||
- { type: 'boolean', value: True, key: 'sample_bool_2'}
|
||||
- { type: 'date', value: "2019-02-19 10:10:10", key: 'sample_date'}
|
||||
|
|
Loading…
Reference in a new issue