1
0
Fork 0
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:
Andrew Klychkov 2020-07-21 17:12:21 +03:00 committed by GitHub
parent d7aabcceed
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

@ -0,0 +1,2 @@
bugfixes:
- osx_defaults - fix handling negative integers (https://github.com/ansible-collections/community.general/issues/134).

View file

@ -169,6 +169,14 @@ class OSXDefaults(object):
# /init --------------------------------------------------------------- }}} # /init --------------------------------------------------------------- }}}
# tools --------------------------------------------------------------- {{{ # 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 @staticmethod
def _convert_type(data_type, value): def _convert_type(data_type, value):
""" Converts value to given type """ """ 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)) "Invalid date value: {0}. Required format yyy-mm-dd hh:mm:ss.".format(repr(value))
) )
elif data_type in ["int", "integer"]: 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))) raise OSXDefaultsException("Invalid integer value: {0}".format(repr(value)))
return int(value) return int(value)
elif data_type == "float": elif data_type == "float":

View file

@ -177,6 +177,7 @@
with_items: &data_type with_items: &data_type
- { type: 'int', value: 1, key: 'sample_int'} - { type: 'int', value: 1, key: 'sample_int'}
- { type: 'integer', value: 1, key: 'sample_int_2'} - { type: 'integer', value: 1, key: 'sample_int_2'}
- { type: 'integer', value: -1, key: 'negative_int'}
- { type: 'bool', value: True, key: 'sample_bool'} - { type: 'bool', value: True, key: 'sample_bool'}
- { type: 'boolean', value: True, key: 'sample_bool_2'} - { type: 'boolean', value: True, key: 'sample_bool_2'}
- { type: 'date', value: "2019-02-19 10:10:10", key: 'sample_date'} - { type: 'date', value: "2019-02-19 10:10:10", key: 'sample_date'}