Merge pull request #26122 from hashicorp/alisdair/document-jsonencode-html-escape-behaviour

Document jsonencode HTML escape behaviour
This commit is contained in:
Alisdair McDiarmid 2020-09-04 10:45:50 -04:00 committed by GitHub
commit 42753e7dcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -472,6 +472,12 @@ func TestFunctions(t *testing.T) {
`jsonencode({"hello"="world"})`, `jsonencode({"hello"="world"})`,
cty.StringVal("{\"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": { "keys": {

View File

@ -37,6 +37,11 @@ types, passing the `jsonencode` result to `jsondecode` will not produce an
identical value, but the automatic type conversion rules mean that this is identical value, but the automatic type conversion rules mean that this is
rarely a problem in practice. rarely a problem in practice.
When encoding strings, this function escapes some characters using
Unicode escape sequences: replacing `<`, `>`, `&`, `U+2028`, and `U+2029` with
`\u003c`, `\u003e`, `\u0026`, `\u2028`, and `\u2029`. This is to preserve
compatibility with Terraform 0.11 behavior.
## Examples ## Examples
``` ```