All contributions

go-playground/form

form

A Go library that decodes url.Values, the data from forms and query strings, into structs and encodes it back, with array and map support.

Language
Go
GitHub stars
935
Merged changes
1

What we changed

The decoder no longer panics when a custom type function returns nil for a pointer field and leaves the field empty instead. A populated pointer from that function still ends up in the struct.

What this work shows

  • Go reflection (reflect)
  • Form data decoding
  • Regression tests after a reverted fix
What was broken

A panic on an empty pointer value

A custom type function registered for a pointer returns nil when the field is empty. The decoder passed that nil to reflect.Value.Set and panicked with "call of reflect.Value.Set on zero Value". An earlier fix for this bug had been reverted because it broke the populated pointer case.

How we fixed it

nil leaves the field alone

setFieldByType checks whether the function returned nil before calling Set, and if so leaves the field at its zero value. Any other result is set as before, and a test covers both nil and a pointer to a populated struct.

#77

Merged change 1

  1. #77 Fix panic when a custom type function returns nil for a pointer field Merged 8 September 2026

What it taught us

This bug had been fixed once and reverted because the fix broke another case, so we read that history and put the guard exactly where the value is produced. The test covers both cases: nil and a populated pointer.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.