fix: fix numberic regexp

This commit is contained in:
vicanso 2022-02-19 16:12:53 +08:00
parent 78ba3017ae
commit edee23a6dd
2 changed files with 8 additions and 1 deletions

View file

@ -76,7 +76,7 @@ type EChartsSeriesData struct {
} }
type _EChartsSeriesData EChartsSeriesData type _EChartsSeriesData EChartsSeriesData
var numericRep = regexp.MustCompile(`^[-+]?[0-9]+(?:\\.[0-9]+)?$`) var numericRep = regexp.MustCompile(`^[-+]?[0-9]+(?:\.[0-9]+)?$`)
func (es *EChartsSeriesData) UnmarshalJSON(data []byte) error { func (es *EChartsSeriesData) UnmarshalJSON(data []byte) error {
data = bytes.TrimSpace(data) data = bytes.TrimSpace(data)

View file

@ -256,6 +256,13 @@ func TestEChartsSeriesData(t *testing.T) {
Value: 123, Value: 123,
}, esd) }, esd)
esd = EChartsSeriesData{}
err = esd.UnmarshalJSON([]byte(`2.1`))
assert.Nil(err)
assert.Equal(EChartsSeriesData{
Value: 2.1,
}, esd)
esd = EChartsSeriesData{} esd = EChartsSeriesData{}
err = esd.UnmarshalJSON([]byte(`{ err = esd.UnmarshalJSON([]byte(`{
"value": 123.12, "value": 123.12,