From edee23a6ddd17252de9484b0a678c356b15c818a Mon Sep 17 00:00:00 2001 From: vicanso Date: Sat, 19 Feb 2022 16:12:53 +0800 Subject: [PATCH] fix: fix numberic regexp --- echarts.go | 2 +- echarts_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/echarts.go b/echarts.go index 6de8dc4..19659a8 100644 --- a/echarts.go +++ b/echarts.go @@ -76,7 +76,7 @@ type EChartsSeriesData struct { } 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 { data = bytes.TrimSpace(data) diff --git a/echarts_test.go b/echarts_test.go index 67fabf6..e484b85 100644 --- a/echarts_test.go +++ b/echarts_test.go @@ -256,6 +256,13 @@ func TestEChartsSeriesData(t *testing.T) { Value: 123, }, esd) + esd = EChartsSeriesData{} + err = esd.UnmarshalJSON([]byte(`2.1`)) + assert.Nil(err) + assert.Equal(EChartsSeriesData{ + Value: 2.1, + }, esd) + esd = EChartsSeriesData{} err = esd.UnmarshalJSON([]byte(`{ "value": 123.12,