diff --git a/Makefile b/Makefile index 7b9ac94..66cc402 100644 --- a/Makefile +++ b/Makefile @@ -18,10 +18,12 @@ generate: build ./tests/custom_map_key_type.go \ ./tests/embedded_type.go \ ./tests/reference_to_pointer.go \ + ./tests/html.go \ bin/easyjson -all ./tests/data.go bin/easyjson -all ./tests/nothing.go bin/easyjson -all ./tests/errors.go + bin/easyjson -all ./tests/html.go bin/easyjson -snake_case ./tests/snake.go bin/easyjson -omit_empty ./tests/omitempty.go bin/easyjson -build_tags=use_easyjson ./benchmark/data.go diff --git a/tests/html.go b/tests/html.go new file mode 100644 index 0000000..575e760 --- /dev/null +++ b/tests/html.go @@ -0,0 +1,5 @@ +package tests + +type Struct struct { + Test string +} diff --git a/tests/html_test.go b/tests/html_test.go new file mode 100644 index 0000000..b579936 --- /dev/null +++ b/tests/html_test.go @@ -0,0 +1,33 @@ +package tests + +import ( + "testing" + + "github.com/mailru/easyjson/jwriter" +) + +func TestHTML(t *testing.T) { + s := Struct{ + Test: "test", + } + + j := jwriter.Writer{ + NoEscapeHTML: false, + } + s.MarshalEasyJSON(&j) + + data, _ := j.BuildBytes() + + if string(data) != `{"Test":"\u003cb\u003etest\u003c/b\u003e"}` { + t.Fatal("EscapeHTML error:", string(data)) + } + + j.NoEscapeHTML = true + s.MarshalEasyJSON(&j) + + data, _ = j.BuildBytes() + + if string(data) != `{"Test":"test"}` { + t.Fatal("NoEscapeHTML error:", string(data)) + } +}