Remove BC escaped double quote behavior
When we switched to the current edition of the HCL parser, we inadvertently broke some undocumented behavior where users could successfully used escaped double quotes in a nested interpolation like this: foo = "${somefunc(\"somearg\")}" The proper syntax here is: foo = "${somefunc("somearg")}" Because once you are inside the interpolation braces, the "quoting context" is different. At the time, while we didn't like the fact that the non-standard syntax was in the wild, we didn't want to break BC, so we treated it as a bug and fixed it in #62. Now that we are at the moment of a major Terraform release, we can yank the BC compatible behavior, which fixes a currently broken use case - there is no way to express strings with double quotes in them from inside interpolation braces. foo = "${somefunc("\"inquotes\"")}" After merge and a dep upgrade, this will take care of https://github.com/hashicorp/terraform/issues/5550
This commit is contained in:
parent
d7400db714
commit
2fb7c957a4
@ -64,14 +64,7 @@ func TestDecode_interface(t *testing.T) {
|
||||
"bar": "new\nline",
|
||||
"qax": `slash\:colon`,
|
||||
"nested": `${HH\:mm\:ss}`,
|
||||
"nestedquotes": `${"okay"}`,
|
||||
},
|
||||
},
|
||||
{
|
||||
"interpolate_escape.hcl",
|
||||
false,
|
||||
map[string]interface{}{
|
||||
"foo": "${file(\"bing/bong.txt\")}",
|
||||
"nestedquotes": `${"\"stringwrappedinquotes\""}`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -49,8 +49,7 @@ func Unquote(s string) (t string, err error) {
|
||||
for len(s) > 0 {
|
||||
// If we're starting a '${}' then let it through un-unquoted.
|
||||
// Specifically: we don't unquote any characters within the `${}`
|
||||
// section, except for escaped quotes and escaped backslashes, which we
|
||||
// handle specifically.
|
||||
// section, except for escaped backslashes, which we handle specifically.
|
||||
if s[0] == '$' && len(s) > 1 && s[1] == '{' {
|
||||
buf = append(buf, '$', '{')
|
||||
s = s[2:]
|
||||
@ -65,12 +64,12 @@ func Unquote(s string) (t string, err error) {
|
||||
|
||||
s = s[size:]
|
||||
|
||||
// We special case escaped double quotes and escaped backslashes in
|
||||
// interpolations, converting them to their unescaped equivalents.
|
||||
// We special case escaped backslashes in interpolations, converting
|
||||
// them to their unescaped equivalents.
|
||||
if r == '\\' {
|
||||
q, _ := utf8.DecodeRuneInString(s)
|
||||
switch q {
|
||||
case '"', '\\':
|
||||
case '\\':
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ var unquotetests = []unQuoteTest{
|
||||
{`"\a\b\f\n\r\t\v\\\""`, "\a\b\f\n\r\t\v\\\""},
|
||||
{`"'"`, "'"},
|
||||
{`"${file("foo")}"`, `${file("foo")}`},
|
||||
{`"${file(\"foo\")}"`, `${file("foo")}`},
|
||||
{`"${file("\"foo\"")}"`, `${file("\"foo\"")}`},
|
||||
{`"echo ${var.region}${element(split(",",var.zones),0)}"`,
|
||||
`echo ${var.region}${element(split(",",var.zones),0)}`},
|
||||
{`"${HH\\:mm\\:ss}"`, `${HH\:mm\:ss}`},
|
||||
|
@ -50,7 +50,7 @@ func TestTokenValue(t *testing.T) {
|
||||
{Token{Type: IDENT, Text: `foo`}, "foo"},
|
||||
{Token{Type: STRING, Text: `"foo"`}, "foo"},
|
||||
{Token{Type: STRING, Text: `"foo\nbar"`}, "foo\nbar"},
|
||||
{Token{Type: STRING, Text: `"${file(\"foo\")}"`}, `${file("foo")}`},
|
||||
{Token{Type: STRING, Text: `"${file("foo")}"`}, `${file("foo")}`},
|
||||
{Token{Type: HEREDOC, Text: "<<EOF\nfoo\nbar\nEOF"}, "foo\nbar"},
|
||||
}
|
||||
|
||||
|
@ -3,4 +3,4 @@ bar = "new\nline"
|
||||
qux = "back\\slash"
|
||||
qax = "slash\\:colon"
|
||||
nested = "${HH\\:mm\\:ss}"
|
||||
nestedquotes = "${\"okay\"}"
|
||||
nestedquotes = "${"\"stringwrappedinquotes\""}"
|
||||
|
@ -1 +0,0 @@
|
||||
foo="${file(\"bing/bong.txt\")}"
|
Loading…
Reference in New Issue
Block a user