From 5612ebd9681935b8db56922b1648bbb33c5cbd76 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Thu, 19 Nov 2015 13:56:32 -0600 Subject: [PATCH] Handle multiple interpolations in string. A user testing an RC release of Terraform 0.6.7 found the following string unexpectedly caused a syntax error: "echo ${var.region}${element(split(",",var.zones),0)}" This fixes the error and covers it with a test. --- hcl/strconv/quote.go | 5 +++++ hcl/strconv/quote_test.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/hcl/strconv/quote.go b/hcl/strconv/quote.go index 986872e..e87ac63 100644 --- a/hcl/strconv/quote.go +++ b/hcl/strconv/quote.go @@ -86,7 +86,12 @@ func Unquote(s string) (t string, err error) { return "", ErrSyntax } if len(s) == 0 { + // If there's no string left, we're done! break + } else { + // If there's more left, we need to pop back up to the top of the loop + // in case there's another interpolation in this string. + continue } } diff --git a/hcl/strconv/quote_test.go b/hcl/strconv/quote_test.go index e773ac1..4a810aa 100644 --- a/hcl/strconv/quote_test.go +++ b/hcl/strconv/quote_test.go @@ -37,6 +37,8 @@ var unquotetests = []unQuoteTest{ {`"'"`, "'"}, {`"${file("foo")}"`, `${file("foo")}`}, {`"${file(\"foo\")}"`, `${file("foo")}`}, + {`"echo ${var.region}${element(split(",",var.zones),0)}"`, + `echo ${var.region}${element(split(",",var.zones),0)}`}, } var misquoted = []string{