Merge pull request #132 from hashicorp/b-remove-bc-double-quote-behavior
Remove BC escaped double quote behavior
This commit is contained in:
commit
aa7699b7b6
@ -64,14 +64,7 @@ func TestDecode_interface(t *testing.T) {
|
|||||||
"bar": "new\nline",
|
"bar": "new\nline",
|
||||||
"qax": `slash\:colon`,
|
"qax": `slash\:colon`,
|
||||||
"nested": `${HH\:mm\:ss}`,
|
"nested": `${HH\:mm\:ss}`,
|
||||||
"nestedquotes": `${"okay"}`,
|
"nestedquotes": `${"\"stringwrappedinquotes\""}`,
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"interpolate_escape.hcl",
|
|
||||||
false,
|
|
||||||
map[string]interface{}{
|
|
||||||
"foo": "${file(\"bing/bong.txt\")}",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -49,8 +49,7 @@ func Unquote(s string) (t string, err error) {
|
|||||||
for len(s) > 0 {
|
for len(s) > 0 {
|
||||||
// If we're starting a '${}' then let it through un-unquoted.
|
// If we're starting a '${}' then let it through un-unquoted.
|
||||||
// Specifically: we don't unquote any characters within the `${}`
|
// Specifically: we don't unquote any characters within the `${}`
|
||||||
// section, except for escaped quotes and escaped backslashes, which we
|
// section, except for escaped backslashes, which we handle specifically.
|
||||||
// handle specifically.
|
|
||||||
if s[0] == '$' && len(s) > 1 && s[1] == '{' {
|
if s[0] == '$' && len(s) > 1 && s[1] == '{' {
|
||||||
buf = append(buf, '$', '{')
|
buf = append(buf, '$', '{')
|
||||||
s = s[2:]
|
s = s[2:]
|
||||||
@ -65,12 +64,12 @@ func Unquote(s string) (t string, err error) {
|
|||||||
|
|
||||||
s = s[size:]
|
s = s[size:]
|
||||||
|
|
||||||
// We special case escaped double quotes and escaped backslashes in
|
// We special case escaped backslashes in interpolations, converting
|
||||||
// interpolations, converting them to their unescaped equivalents.
|
// them to their unescaped equivalents.
|
||||||
if r == '\\' {
|
if r == '\\' {
|
||||||
q, _ := utf8.DecodeRuneInString(s)
|
q, _ := utf8.DecodeRuneInString(s)
|
||||||
switch q {
|
switch q {
|
||||||
case '"', '\\':
|
case '\\':
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ var unquotetests = []unQuoteTest{
|
|||||||
{`"\a\b\f\n\r\t\v\\\""`, "\a\b\f\n\r\t\v\\\""},
|
{`"\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")}`},
|
{`"${file("\"foo\"")}"`, `${file("\"foo\"")}`},
|
||||||
{`"echo ${var.region}${element(split(",",var.zones),0)}"`,
|
{`"echo ${var.region}${element(split(",",var.zones),0)}"`,
|
||||||
`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}`},
|
||||||
|
@ -50,7 +50,7 @@ func TestTokenValue(t *testing.T) {
|
|||||||
{Token{Type: IDENT, Text: `foo`}, "foo"},
|
{Token{Type: IDENT, Text: `foo`}, "foo"},
|
||||||
{Token{Type: STRING, Text: `"foo"`}, "foo"},
|
{Token{Type: STRING, Text: `"foo"`}, "foo"},
|
||||||
{Token{Type: STRING, Text: `"foo\nbar"`}, "foo\nbar"},
|
{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"},
|
{Token{Type: HEREDOC, Text: "<<EOF\nfoo\nbar\nEOF"}, "foo\nbar"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,4 +3,4 @@ bar = "new\nline"
|
|||||||
qux = "back\\slash"
|
qux = "back\\slash"
|
||||||
qax = "slash\\:colon"
|
qax = "slash\\:colon"
|
||||||
nested = "${HH\\:mm\\:ss}"
|
nested = "${HH\\:mm\\:ss}"
|
||||||
nestedquotes = "${\"okay\"}"
|
nestedquotes = "${"\"stringwrappedinquotes\""}"
|
||||||
|
@ -1 +0,0 @@
|
|||||||
foo="${file(\"bing/bong.txt\")}"
|
|
Loading…
x
Reference in New Issue
Block a user