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:
parent
05be7a778d
commit
2fd69cb0a5
@ -342,6 +342,14 @@ func TestDecode_interface(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"interpolate.json",
|
||||
false,
|
||||
map[string]interface{}{
|
||||
"default": `${replace("europe-west", "-", " ")}`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
@ -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"
|
||||
|
7
json/parser/test-fixtures/bad_input_tf_8110.json
Normal file
7
json/parser/test-fixtures/bad_input_tf_8110.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variable": {
|
||||
"poc": {
|
||||
"default": "${replace("europe-west", "-", " ")}"
|
||||
}
|
||||
}
|
||||
}
|
7
json/parser/test-fixtures/good_input_tf_8110.json
Normal file
7
json/parser/test-fixtures/good_input_tf_8110.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variable": {
|
||||
"poc": {
|
||||
"default": "${replace(\"europe-west\", \"-\", \" \")}"
|
||||
}
|
||||
}
|
||||
}
|
@ -296,7 +296,7 @@ func (s *Scanner) scanString() {
|
||||
return
|
||||
}
|
||||
|
||||
if ch == '"' && braces == 0 {
|
||||
if ch == '"' {
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -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"`},
|
||||
|
3
test-fixtures/interpolate.json
Normal file
3
test-fixtures/interpolate.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"default": "${replace(\"europe-west\", \"-\", \" \")}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user