From c7568ccceb1bfa2c0c15451c74d8e4a0fd8d10aa Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Thu, 3 Sep 2020 15:16:49 -0400 Subject: [PATCH] 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. --- lang/functions_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lang/functions_test.go b/lang/functions_test.go index d27a487af9..d226a32aaf 100644 --- a/lang/functions_test.go +++ b/lang/functions_test.go @@ -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"=""})`, + cty.StringVal("{\"hello\":\"\\u003ccats \\u0026 kittens\\u003e\"}"), + }, }, "keys": {