fix: the time.Duration type panics due to numerical values (#4944)

Co-authored-by: sam.yang <sam.yang@yijinin.com>
This commit is contained in:
wanwu
2025-06-12 23:11:07 +08:00
committed by GitHub
parent a99c14da4a
commit 4cacc4d9d3
2 changed files with 20 additions and 1 deletions

View File

@@ -622,7 +622,11 @@ func (u *Unmarshaler) processFieldNotFromString(fieldType reflect.Type, value re
return u.fillSliceFromString(fieldType, value, mapValue, fullName)
case valueKind == reflect.String && derefedFieldType == durationType:
return fillDurationValue(fieldType, value, mapValue.(string))
v, ok := mapValue.(string)
if !ok {
return fmt.Errorf("unexpected type %T, expected a string value for field %s", mapValue, fullName)
}
return fillDurationValue(fieldType, value, v)
case valueKind == reflect.String && typeKind == reflect.Struct && u.implementsUnmarshaler(fieldType):
return u.fillUnmarshalerStruct(fieldType, value, mapValue.(string))
default: