Closed losinggeneration closed 10 years ago
Good find, thanks for the reproducible case.
Can you confirm that changing line 200 of binding.go to this fixes the problem:
(field.Type.Kind() == reflect.Ptr && !reflect.DeepEqual(zero, fieldValue) &&
field.Type.Elem().Kind() == reflect.Struct) {
Notice the extra condition that the field's type's Elem()
must be a Struct kind before going into validate it.
That does indeed look like it fixes the problem. The test case doesn't work here because it's comparing the pointer locations and not the underlying data.
Awesome, thank you! I'll get the fix rolled out shortly.
If you have a basic type that's a pointer, deserialization doesn't happen correctly. For instance:
causes a panic during the ValidateStruct step. The validation incorrectly assumes if it's a pointer, it's a pointer to a struct.
A full, stand alone test would be the following
With a curl test of
I've also done a quick JSON test case with the following commit: https://github.com/losinggeneration/binding/commit/58a8515eb2be7b5226273e09fbd660b9f8a17457