lang: Add test for jsonencode entity escaping

The encoding/json package escapes some HTML-specific characters to
prevent JSON from being misinterpreted when in the context of an HTML
document. Terraform 0.11 used this behaviour, and to preserve backwards
compatibility we are continuing to do so moving forward.

This commit adds an explicit test to document that this is intentional,
not a bug.
This commit is contained in:
Alisdair McDiarmid 2020-09-03 15:16:49 -04:00
parent 79e35941f5
commit c7568ccceb
1 changed files with 6 additions and 0 deletions

View File

@ -472,6 +472,12 @@ func TestFunctions(t *testing.T) {
`jsonencode({"hello"="world"})`,
cty.StringVal("{\"hello\":\"world\"}"),
},
// We are intentionally choosing to escape <, >, and & characters
// to preserve backwards compatibility with Terraform 0.11
{
`jsonencode({"hello"="<cats & kittens>"})`,
cty.StringVal("{\"hello\":\"\\u003ccats \\u0026 kittens\\u003e\"}"),
},
},
"keys": {