fix: string null value should error close #57143 (#61842)

close pingcap/tidb#57143
This commit is contained in:
yihong
2025-06-20 01:38:36 +08:00
committed by GitHub
parent 534ddf33b3
commit ffb9bf06f5
2 changed files with 8 additions and 2 deletions

View File

@ -220,6 +220,12 @@ func ZeroCopyDeserializeVectorFloat32(b []byte) (VectorFloat32, []byte, error) {
// ParseVectorFloat32 parses a string into a vector.
func ParseVectorFloat32(s string) (VectorFloat32, error) {
// issue #57143 jsoniter parse null will return as []
// Trim whitespace and check for null string and reject it
if strings.TrimSpace(s) == "null" {
return ZeroVectorFloat32, errors.Errorf("Invalid vector text: %s", s)
}
var values []float32
var valueError error
// We explicitly use a JSON float parser to reject other JSON types.

View File

@ -61,9 +61,9 @@ func TestVectorParse(t *testing.T) {
require.NotNil(t, err)
require.True(t, v.IsZeroValue())
// Note: Currently we will parse "null" into [].
// "null" string should return error, not empty vector
v, err = types.ParseVectorFloat32(`null`)
require.Nil(t, err)
require.NotNil(t, err)
require.True(t, v.IsZeroValue())
v, err = types.ParseVectorFloat32(`"json_str"`)