fix: strict flag values, MI NULL properties and container without HCS (#2553)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-08 19:43:38 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent b6d75ffb71
commit f8ada403f2
9 changed files with 176 additions and 3 deletions
+7
View File
@@ -222,6 +222,13 @@ func unmarshalInstance(instance *Instance, fields []miField, structValue reflect
// setField assigns the value of element to field, rejecting Go field types that
// cannot hold the MI value instead of letting the reflect package panic.
func setField(miTag string, field reflect.Value, element *Element) error {
if element.IsNull() {
// MI makes no promise about the contents of a NULL element's union.
// Check the Go type against a zeroed copy, so a mismatched field fails
// whether or not the property is NULL, but leave the field untouched.
return setField(miTag, reflect.New(field.Type()).Elem(), &Element{valueType: element.valueType})
}
switch element.valueType {
case ValueTypeBOOLEAN:
if field.Kind() != reflect.Bool {
+5
View File
@@ -69,6 +69,11 @@ func TestSetField(t *testing.T) {
{"char16_overflows_uint8", Element{value: 0x20AC, valueType: ValueTypeCHAR16}, newField[uint8](), nil, true},
{"char16_into_bool", Element{value: 'A', valueType: ValueTypeCHAR16}, newField[bool](), nil, true},
{"null_uint32_keeps_zero_value", Element{value: 42, valueType: ValueTypeUINT32, flags: flagNull}, newField[uint32](), uint32(0), false},
{"null_real64_keeps_zero_value", Element{value: uintptr(math.Float64bits(9.875)), valueType: ValueTypeREAL64, flags: flagNull}, newField[float64](), float64(0), false},
{"null_char16_into_string_keeps_zero_value", Element{value: 'A', valueType: ValueTypeCHAR16, flags: flagNull}, newField[string](), "", false},
{"null_still_rejects_wrong_type", Element{value: 42, valueType: ValueTypeUINT32, flags: flagNull}, newField[string](), nil, true},
{"uint16a_into_wrong_slice", Element{value: 0, valueType: ValueTypeUINT16A}, newField[[]uint32](), nil, true},
{"unsupported_type", Element{value: 0, valueType: ValueTypeDATETIME}, newField[string](), nil, true},
}