mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Fix only_if statements referencing non-string types
This fixes e.g. only_if: ${task.changed} which would always evaluate to true due to it having been replaced by a string for its boolean value. Also adds a test case to ensure it doesn't get missed again.
This commit is contained in:
parent
151085c745
commit
b55ef665ba
2 changed files with 16 additions and 5 deletions
|
@ -269,8 +269,9 @@ def varReplace(raw, vars, do_repr=False, depth=0):
|
|||
# original)
|
||||
|
||||
try:
|
||||
replacement = unicode(_varLookup(m.group(2), vars, depth))
|
||||
replacement = varReplace(replacement, vars, depth=depth + 1)
|
||||
replacement = _varLookup(m.group(2), vars, depth)
|
||||
if isinstance(replacement, (str, unicode)):
|
||||
replacement = varReplace(replacement, vars, depth=depth + 1)
|
||||
except VarNotFoundException:
|
||||
replacement = m.group()
|
||||
|
||||
|
@ -282,9 +283,9 @@ def varReplace(raw, vars, do_repr=False, depth=0):
|
|||
(raw[start - 1] == '"' and raw[end] == '"'))):
|
||||
start -= 1
|
||||
end += 1
|
||||
done.append(raw[:start]) # Keep stuff leading up to token
|
||||
done.append(replacement) # Append replacement value
|
||||
raw = raw[end:] # Continue with remainder of string
|
||||
done.append(raw[:start]) # Keep stuff leading up to token
|
||||
done.append(unicode(replacement)) # Append replacement value
|
||||
raw = raw[end:] # Continue with remainder of string
|
||||
|
||||
return ''.join(done)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue