Skip to content

Commit d260de1

Browse files
committed
fix issue gogf#1750
1 parent be77779 commit d260de1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

util/gconv/gconv.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,18 @@ func checkJsonAndUnmarshalUseNumber(any interface{}, target interface{}) bool {
264264
switch r := any.(type) {
265265
case []byte:
266266
if json.Valid(r) {
267-
_ = json.UnmarshalUseNumber(r, &target)
267+
if err := json.UnmarshalUseNumber(r, &target); err != nil {
268+
return false
269+
}
268270
return true
269271
}
270272

271273
case string:
272274
anyAsBytes := []byte(r)
273275
if json.Valid(anyAsBytes) {
274-
_ = json.UnmarshalUseNumber(anyAsBytes, &target)
276+
if err := json.UnmarshalUseNumber(anyAsBytes, &target); err != nil {
277+
return false
278+
}
275279
return true
276280
}
277281
}

util/gconv/gconv_z_unit_slice_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func Test_Strings(t *testing.T) {
103103
}
104104
t.AssertEQ(gconv.Strings(array), []string{"1", "2", "3"})
105105
})
106+
// https://github.com/gogf/gf/issues/1750
107+
gtest.C(t, func(t *gtest.T) {
108+
t.AssertEQ(gconv.Strings("123"), []string{"123"})
109+
})
106110
}
107111

108112
func Test_Slice_Interfaces(t *testing.T) {

0 commit comments

Comments
 (0)