json: interpolations have to be escaped

At some point we ignored the " in interpolations. We do this for HCL and
it is correct but this is invalid JSON syntax and for JSON we've always
had the stance that we have to escape them.
This commit is contained in:
Mitchell Hashimoto 2016-09-02 09:31:47 -07:00 committed by James Nugent
parent 05be7a778d
commit 2fd69cb0a5
7 changed files with 34 additions and 2 deletions

View File

@ -342,6 +342,14 @@ func TestDecode_interface(t *testing.T) {
},
},
},
{
"interpolate.json",
false,
map[string]interface{}{
"default": `${replace("europe-west", "-", " ")}`,
},
},
}
for _, tc := range cases {

View File

@ -315,6 +315,14 @@ func TestParse(t *testing.T) {
"bad_input_128.json",
true,
},
{
"bad_input_tf_8110.json",
true,
},
{
"good_input_tf_8110.json",
false,
},
}
const fixtureDir = "./test-fixtures"

View File

@ -0,0 +1,7 @@
{
"variable": {
"poc": {
"default": "${replace("europe-west", "-", " ")}"
}
}
}

View File

@ -0,0 +1,7 @@
{
"variable": {
"poc": {
"default": "${replace(\"europe-west\", \"-\", \" \")}"
}
}
}

View File

@ -296,7 +296,7 @@ func (s *Scanner) scanString() {
return
}
if ch == '"' && braces == 0 {
if ch == '"' {
break
}

View File

@ -32,7 +32,6 @@ var tokenLists = map[string][]tokenPair{
{token.STRING, `" "`},
{token.STRING, `"a"`},
{token.STRING, `"本"`},
{token.STRING, `"${file("foo")}"`},
{token.STRING, `"${file(\"foo\")}"`},
{token.STRING, `"\a"`},
{token.STRING, `"\b"`},

View File

@ -0,0 +1,3 @@
{
"default": "${replace(\"europe-west\", \"-\", \" \")}"
}