[config] coerce more to string when 'type: str' (#72172)

Change:
- When a plugin defines `type: str` on a parameter, treat more kinds of
  input as a string instead of whatever it is parsed as.

Test Plan:
- New unit tests
- CI

Signed-off-by: Rick Elrod <rick@elrod.me>
pull/72218/head
Rick Elrod 4 years ago committed by GitHub
parent 6e7a40dd94
commit 3b40c6f3b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- "config - more types are now automatically coerced to string when ``type: str`` is used and the value is parsed as a different type"

@ -149,7 +149,7 @@ def ensure_type(value, value_type, origin=None):
errmsg = 'dictionary'
elif value_type in ('str', 'string'):
if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode)):
if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode, bool, int, float, complex)):
value = unquote(to_text(value, errors='surrogate_or_strict'))
else:
errmsg = 'string'

@ -60,6 +60,18 @@ ensure_test_data = [
('a', 'string', string_types),
('Café', 'string', string_types),
('', 'string', string_types),
('29', 'str', string_types),
('13.37', 'str', string_types),
('123j', 'string', string_types),
('0x123', 'string', string_types),
('true', 'string', string_types),
('True', 'string', string_types),
(0, 'str', string_types),
(29, 'str', string_types),
(13.37, 'str', string_types),
(123j, 'string', string_types),
(0x123, 'string', string_types),
(True, 'string', string_types),
('None', 'none', type(None))
]

Loading…
Cancel
Save