diff --git a/Makefile b/Makefile index b99fa6962..5ee5fb215 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ CPU_avx2 := amd64 TMPL_avx := fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64 TMPL_avx2 := fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64 -CFLAGS_avx := -msse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -DDEBUG=1 -CFLAGS_avx2 := -msse4 -mavx -mavx2 -DUSE_AVX=1 -DUSE_AVX2=1 +CFLAGS_avx := -msse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 +CFLAGS_avx2 := -msse4 -mavx -mavx2 -DUSE_AVX=1 -DUSE_AVX2=1 CC_amd64 := clang ASM2ASM_amd64 := tools/asm2asm/asm2asm.py diff --git a/api.go b/api.go index 9456d81b0..88f8f9ed3 100644 --- a/api.go +++ b/api.go @@ -64,6 +64,9 @@ import ( // CopyString indicates decoder to decode string values by copying instead of referring. CopyString bool + // ValidString indicates decoder to valid string values: decoder will return errors when + // invalid UTF-8 chars or unescaped control chars(\u0000-\u001f). + ValidString bool } var ( diff --git a/sonic.go b/sonic.go index aebb9c917..7fa65598a 100644 --- a/sonic.go +++ b/sonic.go @@ -61,6 +61,8 @@ type frozenConfig struct { // Froze convert the Config to API func (cfg Config) Froze() API { api := &frozenConfig{Config: cfg} + + // configure encoder options: if cfg.EscapeHTML { api.encoderOpts |= encoder.EscapeHTML } @@ -73,6 +75,11 @@ func (cfg Config) Froze() API { if cfg.NoQuoteTextMarshaler { api.encoderOpts |= encoder.NoQuoteTextMarshaler } + if cfg.NoNullSliceOrMap { + api.encoderOpts |= encoder.NoNullSliceOrMap + } + + // configure decoder options: if cfg.UseInt64 { api.decoderOpts |= decoder.OptionUseInt64 } @@ -85,8 +92,8 @@ func (cfg Config) Froze() API { if cfg.CopyString { api.decoderOpts |= decoder.OptionCopyString } - if cfg.NoNullSliceOrMap { - api.encoderOpts |= encoder.NoNullSliceOrMap + if cfg.ValidString { + api.decoderOpts |= decoder.OptionValidateString } return api } @@ -111,7 +118,6 @@ func (cfg *frozenConfig) MarshalIndent(val interface{}, prefix, indent string) ( func (cfg *frozenConfig) UnmarshalFromString(buf string, val interface{}) error { dec := decoder.NewDecoder(buf) dec.SetOptions(cfg.decoderOpts) - dec.ValidString() err := dec.Decode(val) pos := dec.Pos()