---
title: "form: decoder panic on a nil custom type value in Go"
description: "A fix in the form library in Go: the url.Values decoder no longer panics when a custom type function returns nil for a pointer field."
url: "https://vulcode.com/en/opensource/contributions/go-form"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/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.

[See the repository](https://github.com/go-playground/form) [All contributions](https://vulcode.com/en/opensource/contributions)

- **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](https://github.com/go-playground/form/pull/77)

## Merged change 1

- [#77 Fix panic when a custom type function returns nil for a pointer field Merged 8 September 2026](https://github.com/go-playground/form/pull/77)

## 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](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
