Merge pull request #132 from hashicorp/b-remove-bc-double-quote-behavior

Remove BC escaped double quote behavior
This commit is contained in:
Paul Hinze 2016-06-16 23:00:17 +02:00 committed by GitHub
commit aa7699b7b6
6 changed files with 8 additions and 17 deletions

View File

@ -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\""}`,
},
},
{

View File

@ -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
}
}

View File

@ -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}`},

View File

@ -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"},
}

View File

@ -3,4 +3,4 @@ bar = "new\nline"
qux = "back\\slash"
qax = "slash\\:colon"
nested = "${HH\\:mm\\:ss}"
nestedquotes = "${\"okay\"}"
nestedquotes = "${"\"stringwrappedinquotes\""}"

View File

@ -1 +0,0 @@
foo="${file(\"bing/bong.txt\")}"