Skip to content

fix(apiform): encode typed nil readers as empty fields instead of panicking - #125

Closed
Hughhhhcoder wants to merge 1 commit into
openai:mainfrom
Hughhhhcoder:fix/typed-nil-reader-panic
Closed

fix(apiform): encode typed nil readers as empty fields instead of panicking#125
Hughhhhcoder wants to merge 1 commit into
openai:mainfrom
Hughhhhcoder:fix/typed-nil-reader-panic

Conversation

@Hughhhhcoder

Copy link
Copy Markdown

Problem

encodeValue routes any value whose type implements io.Reader into encodeReader before checking whether the value is a typed nil. A typed nil pointer (or nil interface) whose type implements io.Reader therefore reaches encodeReader, which calls io.Copy on a nil receiver and panics.

Fix

Move the nil check for reflect.Pointer and reflect.Interface ahead of the io.Reader interface check, so typed nil values are encoded as empty fields instead of panicking.

Test

Added a regression test in internal/apiform/form_test.go covering typed nil io.Reader values. go test ./internal/apiform/... passes.

@Hughhhhcoder
Hughhhhcoder requested a review from a team as a code owner August 21, 2026 11:47
@Hughhhhcoder
Hughhhhcoder force-pushed the fix/typed-nil-reader-panic branch from 66b0c27 to 189de38 Compare August 24, 2026 04:08
@Hughhhhcoder

Copy link
Copy Markdown
Author

The latest pull-request workflow runs (CI, CodeQL, and Castiron custom code) are completed with action_required. Could a maintainer approve the workflows so they can run? This appears to be a workflow-permission gate rather than a code failure; the focused and package tests pass locally.

@jbeckwith-oai

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This duplicates #89 and the earlier PR #90, which already owns the original report. While reviewing both, I found that the shallow nil check still panicked when a typed-nil pointer was wrapped in an io.Reader-typed map or slice. I have pushed the interface-unwrapping correction and expanded regression coverage to #90, so I am closing this PR in favor of that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants