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
This commit is contained in:
parent
958f740cc3
commit
57d8b68c03
2 changed files with 7 additions and 0 deletions
3
changelogs/fragments/regex-tests-undefined.yml
Normal file
3
changelogs/fragments/regex-tests-undefined.yml
Normal file
|
@ -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…
Reference in a new issue