hcl: don't escape ANYTHING in ${}, let lower layer handle it
This commit is contained in:
parent
99df0eb941
commit
62ebf9354f
@ -63,7 +63,7 @@ func TestDecode_interface(t *testing.T) {
|
||||
"qux": "back\\slash",
|
||||
"bar": "new\nline",
|
||||
"qax": `slash\:colon`,
|
||||
"nested": `${HH\:mm\:ss}`,
|
||||
"nested": `${HH\\:mm\\:ss}`,
|
||||
"nestedquotes": `${"\"stringwrappedinquotes\""}`,
|
||||
},
|
||||
},
|
||||
@ -356,6 +356,20 @@ func TestDecode_interface(t *testing.T) {
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
|
||||
{
|
||||
"escape_backslash.hcl",
|
||||
false,
|
||||
map[string]interface{}{
|
||||
"output": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"one": `${replace(var.sub_domain, ".", "\\.")}`,
|
||||
"two": `${replace(var.sub_domain, ".", "\\\\.")}`,
|
||||
"many": `${replace(var.sub_domain, ".", "\\\\\\\\.")}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
@ -363,7 +363,7 @@ func TestRealExample(t *testing.T) {
|
||||
|
||||
provider "aws" {
|
||||
access_key = "foo"
|
||||
secret_key = "bar"
|
||||
secret_key = "${replace(var.foo, ".", "\\.")}"
|
||||
}
|
||||
|
||||
resource "aws_security_group" "firewall" {
|
||||
@ -416,7 +416,7 @@ EOF
|
||||
{token.STRING, `"foo"`},
|
||||
{token.IDENT, `secret_key`},
|
||||
{token.ASSIGN, `=`},
|
||||
{token.STRING, `"bar"`},
|
||||
{token.STRING, `"${replace(var.foo, ".", "\\.")}"`},
|
||||
{token.RBRACE, `}`},
|
||||
{token.IDENT, `resource`},
|
||||
{token.STRING, `"aws_security_group"`},
|
||||
|
@ -46,7 +46,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 backslashes, which we handle specifically.
|
||||
// section.
|
||||
if s[0] == '$' && len(s) > 1 && s[1] == '{' {
|
||||
buf = append(buf, '$', '{')
|
||||
s = s[2:]
|
||||
@ -61,16 +61,6 @@ func Unquote(s string) (t string, err error) {
|
||||
|
||||
s = s[size:]
|
||||
|
||||
// We special case escaped backslashes in interpolations, converting
|
||||
// them to their unescaped equivalents.
|
||||
if r == '\\' {
|
||||
q, _ := utf8.DecodeRuneInString(s)
|
||||
switch q {
|
||||
case '\\':
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
n := utf8.EncodeRune(runeTmp[:], r)
|
||||
buf = append(buf, runeTmp[:n]...)
|
||||
|
||||
|
@ -39,7 +39,7 @@ var unquotetests = []unQuoteTest{
|
||||
{`"${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}`},
|
||||
{`"${HH\\:mm\\:ss}"`, `${HH\\:mm\\:ss}`},
|
||||
}
|
||||
|
||||
var misquoted = []string{
|
||||
|
@ -51,6 +51,12 @@ func TestTokenValue(t *testing.T) {
|
||||
{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: `"${replace("foo", ".", "\\.")}"`,
|
||||
},
|
||||
`${replace("foo", ".", "\\.")}`},
|
||||
{Token{Type: HEREDOC, Text: "<<EOF\nfoo\nbar\nEOF"}, "foo\nbar"},
|
||||
}
|
||||
|
||||
|
5
test-fixtures/escape_backslash.hcl
Normal file
5
test-fixtures/escape_backslash.hcl
Normal file
@ -0,0 +1,5 @@
|
||||
output {
|
||||
one = "${replace(var.sub_domain, ".", "\\.")}"
|
||||
two = "${replace(var.sub_domain, ".", "\\\\.")}"
|
||||
many = "${replace(var.sub_domain, ".", "\\\\\\\\.")}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user