mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
add tests for htmlescaping
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package tests
|
||||
|
||||
type Struct struct {
|
||||
Test string
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mailru/easyjson/jwriter"
|
||||
)
|
||||
|
||||
func TestHTML(t *testing.T) {
|
||||
s := Struct{
|
||||
Test: "<b>test</b>",
|
||||
}
|
||||
|
||||
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":"<b>test</b>"}` {
|
||||
t.Fatal("NoEscapeHTML error:", string(data))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user