Skip to content

Commit

Permalink
Merge pull request appuio#5 from Cougar/fix-4
Browse files Browse the repository at this point in the history
Fixes appuio#4 - quote values for YAML parser
  • Loading branch information
dtschan authored Nov 7, 2018
2 parents 53d3551 + 3e2cfa8 commit 23a129c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ini2yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ varRegex = re.compile(" *([a-zA-Z][a-zA-Z0-9_]+)=('[^']+'|\"[^\"]+\"|[^ ]+)")

# Parse host variable and return corresponding YAML object
def parse_value(value):
result = yaml.load("value: " + value)['value']
if ":" in value and not (value.startswith("'") or value.startswith('"')):
result = yaml.load("value: \"" + value + "\"")['value']
else:
result = yaml.load("value: " + value)['value']
if isinstance(result, basestring):
if '\\n' in result: # Use YAML block literal for multi-line strings
return literal_unicode(result.replace('\\n', '\n'))
Expand Down
5 changes: 4 additions & 1 deletion tests/inventory.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ group_double_quoted_string='Hello, World!'
group_unquoted_string=abc
group_list=[1,2,3]
group_dict={a: 1, b: 2}
group_colons_quoted_string='x::'
group_colons_double_quoted_string='x::'
group_colons_unquoted_string=x::


[local]
localhost host_boolean=True host_int=42 host_quoted_string='Hello, World!' host_double_quoted_string='Hello, World!' host_unquoted_string=abc
localhost host_boolean=True host_int=42 host_quoted_string='Hello, World!' host_double_quoted_string='Hello, World!' host_unquoted_string=abc host_colon_quoted_string='x::' host_colon_double_quoted_string='x::' host_colons_unquoted_string=x::

0 comments on commit 23a129c

Please sign in to comment.