Skip to content

Commit

Permalink
Merge pull request #41 from gruntwork-io/map-parse
Browse files Browse the repository at this point in the history
Allow multiple colons in map values
  • Loading branch information
brikis98 committed Oct 20, 2017
2 parents 1c72eb2 + c53444a commit 66e7653
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions variables/variables.go
Expand Up @@ -290,12 +290,12 @@ func parseStringAsMap(str string) (map[string]string, error) {

for _, keyAndValue := range keysAndValues {
parts := strings.Split(keyAndValue, ":")
if len(parts) != 2 {
if len(parts) < 2 {
return nil, errors.WithStackTrace(ParseError{ExpectedType: "map", ExpectedFormat: "<key>:<value> for each item in the map", ActualFormat: str})
}

key := parts[0]
value := parts[1]
key := strings.Join(parts[:(len(parts) - 1)], ":")
value := parts[len(parts) - 1]

result[key] = value
}
Expand Down
1 change: 1 addition & 0 deletions variables/variables_test.go
Expand Up @@ -39,6 +39,7 @@ func TestParseStringAsMap(t *testing.T) {
{"empty-map", "map[]", map[string]string{}},
{"one-item", "map[a:b]", map[string]string{"a": "b"}},
{"three-items", "map[a:b c:d e:f]", map[string]string{"a": "b", "c": "d", "e": "f"}},
{"multiple-colons", "map[a:b:c:d:e]", map[string]string{"a:b:c:d": "e"}},
}

for _, testCase := range testCases {
Expand Down

0 comments on commit 66e7653

Please sign in to comment.