Merge pull request #9878 from ansible/handle-quoted-comma-dict-param

Handle quoting of values in dict parameters
This commit is contained in:
Brian Coca 2015-07-27 15:37:27 -04:00
commit 010e58ebfa

View file

@ -1070,7 +1070,32 @@ class AnsibleModule(object):
raise TypeError('unable to evaluate string as dictionary') raise TypeError('unable to evaluate string as dictionary')
return result return result
elif '=' in value: elif '=' in value:
return dict([x.strip().split("=", 1) for x in value.split(",")]) fields = []
field_buffer = []
in_quote = False
in_escape = False
for c in value.strip():
if in_escape:
field_buffer.append(c)
in_escape = False
elif c == '\\':
in_escape = True
elif not in_quote and c in ('\'', '"'):
in_quote = c
elif in_quote and in_quote == c:
in_quote = False
elif not in_quote and c in (',', ' '):
field = ''.join(field_buffer)
if field:
fields.append(field)
field_buffer = []
else:
field_buffer.append(c)
field = ''.join(field_buffer)
if field:
fields.append(field)
return dict(x.split("=", 1) for x in fields)
else: else:
raise TypeError("dictionary requested, could not parse JSON or key=value") raise TypeError("dictionary requested, could not parse JSON or key=value")