mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-17 22:01:07 -07:00
Clean string data run through the template engine
Also strip UnsafeProxy off of low level srings and objects to ensure they don't cause issues later down the road Fixes #12513
This commit is contained in:
parent
ae9b34b1d9
commit
cdc6c5208e
3 changed files with 84 additions and 29 deletions
|
@ -50,6 +50,8 @@
|
|||
# http://code.activestate.com/recipes/496741-object-proxying/
|
||||
# Author: Tomer Filiba
|
||||
|
||||
__all__ = ['UnsafeProxy', 'wrap_var']
|
||||
|
||||
class UnsafeProxy(object):
|
||||
__slots__ = ["_obj", "__weakref__"]
|
||||
def __init__(self, obj):
|
||||
|
@ -149,3 +151,25 @@ class UnsafeProxy(object):
|
|||
ins = object.__new__(theclass)
|
||||
return ins
|
||||
|
||||
def _wrap_dict(v):
|
||||
for k in v.keys():
|
||||
if v[k] is not None and not isinstance(v[k], UnsafeProxy):
|
||||
v[k] = _wrap_var(v[k])
|
||||
return v
|
||||
|
||||
def _wrap_list(v):
|
||||
for idx, item in enumerate(v):
|
||||
if item is not None and not isinstance(item, UnsafeProxy):
|
||||
v[idx] = _wrap_var(item)
|
||||
return v
|
||||
|
||||
def wrap_var(v):
|
||||
if isinstance(v, dict):
|
||||
v = _wrap_dict(v)
|
||||
elif isinstance(v, list):
|
||||
v = _wrap_list(v)
|
||||
else:
|
||||
if v is not None and not isinstance(v, UnsafeProxy):
|
||||
v = UnsafeProxy(v)
|
||||
return v
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue