Use to_text on value to activate _fail_with_undefined_error (#58214)

* Use to_text on value to activate _fail_with_undefined_error. Fixes #12186

* Add comment explaining in depth what to_text gives us
pull/58294/head
Matt Martz 5 years ago committed by GitHub
parent 958f740cc3
commit 57d8b68c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- regex tests - Fail with undefined error if the value is
undefined (https://github.com/ansible/ansible/issues/12186)

@ -24,6 +24,7 @@ import operator as py_operator
from distutils.version import LooseVersion, StrictVersion
from ansible import errors
from ansible.module_utils._text import to_text
from ansible.module_utils.common._collections_compat import MutableMapping, MutableSequence
from ansible.utils.display import Display
@ -114,6 +115,9 @@ def regex(value='', pattern='', ignorecase=False, multiline=False, match_type='s
This is likely only useful for `search` and `match` which already
have their own filters.
'''
# In addition to ensuring the correct type, to_text here will ensure
# _fail_with_undefined_error happens if the value is Undefined
value = to_text(value, errors='surrogate_or_strict')
flags = 0
if ignorecase:
flags |= re.I

Loading…
Cancel
Save