diff --git a/cmd/cue/cmd/testdata/script/export_escape.txtar b/cmd/cue/cmd/testdata/script/export_escape.txtar new file mode 100644 index 00000000000..8cdef651c47 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/export_escape.txtar @@ -0,0 +1,26 @@ +# Verify that export with and without --escape works as expected. + +exec cue export --out json file.cue +cmp stdout stdout.golden + +exec cue export --out json --escape file.cue +cmp stdout stdout-escape.golden + +-- file.cue -- +package hello + +simple: "hello" +specialJSON: #"\ ""# +specialHTML: "& < >" +-- stdout.golden -- +{ + "simple": "hello", + "specialJSON": "\\ \"", + "specialHTML": "\u0026 \u003c \u003e" +} +-- stdout-escape.golden -- +{ + "simple": "hello", + "specialJSON": "\\ \"", + "specialHTML": "\u0026 \u003c \u003e" +} diff --git a/pkg/encoding/json/testdata/gen.txtar b/pkg/encoding/json/testdata/gen.txtar index ca6cbed3903..7070c3c9e1c 100644 --- a/pkg/encoding/json/testdata/gen.txtar +++ b/pkg/encoding/json/testdata/gen.txtar @@ -15,6 +15,10 @@ t8: { y: json.Marshal({a: x}) } t9: json.MarshalStream([{a: 1}, {b: int | *2}]) +t10: json.Marshal({a: #"\ " & < >"#}) +t11: json.HTMLEscape(t10) +t12: json.MarshalStream([{a: #"\ " & < >"#}, {b: ""}]) +t13: json.HTMLEscape(t12) unmarshalStream: { t1: json.UnmarshalStream(#"{"a": 1}{"b": 2}"#) @@ -60,6 +64,18 @@ t9: """ {"a":1} {"b":2} + """ +t10: "{\"a\":\"\\\\ \\\" \\u0026 \\u003c \\u003e\"}" +t11: "{\"a\":\"\\\\ \\\" \\u0026 \\u003c \\u003e\"}" +t12: """ + {"a":"\\\\ \\" \\u0026 \\u003c \\u003e"} + {"b":""} + + """ +t13: """ + {"a":"\\\\ \\" \\u0026 \\u003c \\u003e"} + {"b":""} + """ unmarshalStream: { t1: [{