mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fixed crash on invalid map value in docker labels
This commit is contained in:
parent
d936e24692
commit
2951304647
1 changed files with 15 additions and 3 deletions
|
@ -248,12 +248,18 @@ func Convert(src reflect.Value, dst reflect.Value) E.Error {
|
||||||
dst.Set(src.Convert(dstT))
|
dst.Set(src.Convert(dstT))
|
||||||
return nil
|
return nil
|
||||||
case srcT.Kind() == reflect.Map:
|
case srcT.Kind() == reflect.Map:
|
||||||
|
if src.Len() == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
obj, ok := src.Interface().(SerializedObject)
|
obj, ok := src.Interface().(SerializedObject)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrUnsupportedConversion.Subject(dstT.String() + " to " + srcT.String())
|
return ErrUnsupportedConversion.Subject(dstT.String() + " to " + srcT.String())
|
||||||
}
|
}
|
||||||
return Deserialize(obj, dst.Addr().Interface())
|
return Deserialize(obj, dst.Addr().Interface())
|
||||||
case srcT.Kind() == reflect.Slice:
|
case srcT.Kind() == reflect.Slice:
|
||||||
|
if src.Len() == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if dstT.Kind() != reflect.Slice {
|
if dstT.Kind() != reflect.Slice {
|
||||||
return ErrUnsupportedConversion.Subject(dstT.String() + " to slice")
|
return ErrUnsupportedConversion.Subject(dstT.String() + " to slice")
|
||||||
}
|
}
|
||||||
|
@ -337,10 +343,14 @@ func ConvertString(src string, dst reflect.Value) (convertible bool, convErr E.E
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// yaml like
|
// yaml like
|
||||||
lines := strings.Split(strings.TrimSpace(src), "\n")
|
lines := []string{}
|
||||||
|
src = strings.TrimSpace(src)
|
||||||
|
if src != "" {
|
||||||
|
lines = strings.Split(src, "\n")
|
||||||
for i := range lines {
|
for i := range lines {
|
||||||
lines[i] = strings.TrimSpace(lines[i])
|
lines[i] = strings.TrimSpace(lines[i])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var tmp any
|
var tmp any
|
||||||
switch dst.Kind() {
|
switch dst.Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
|
@ -367,9 +377,11 @@ func ConvertString(src string, dst reflect.Value) (convertible bool, convErr E.E
|
||||||
parts := strings.Split(line, ":")
|
parts := strings.Split(line, ":")
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
errs.Add(ErrMapMissingColon.Subjectf("line %d", i+1))
|
errs.Add(ErrMapMissingColon.Subjectf("line %d", i+1))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if len(parts) > 2 {
|
if len(parts) > 2 {
|
||||||
errs.Add(ErrMapTooManyColons.Subjectf("line %d", i+1))
|
errs.Add(ErrMapTooManyColons.Subjectf("line %d", i+1))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
k := strings.TrimSpace(parts[0])
|
k := strings.TrimSpace(parts[0])
|
||||||
v := strings.TrimSpace(parts[1])
|
v := strings.TrimSpace(parts[1])
|
||||||
|
|
Loading…
Add table
Reference in a new issue