Skip to content

Fix Encoder panic for unsupported pointer fields - #259

Open
skyon0522-ai wants to merge 1 commit into
gorilla:mainfrom
skyon0522-ai:fix-encoder-unsupported-pointers-20261027
Open

skyon0522-ai wants to merge 1 commit into
gorilla:mainfrom
skyon0522-ai:fix-encoder-unsupported-pointers-20261027

Conversation

@skyon0522-ai

Copy link
Copy Markdown

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Go Version Update
  • Dependency Update

Description

Encoder.Encode can panic when a non-nil pointer to an unsupported type reaches a pointer encoder with no underlying callback. Dereference non-nil, unregistered pointers before selecting an encoder so these values take the existing MultiError path. For slices, collect values before replacing the destination entry, preserving it if a later element is unsupported.

This keeps registered pointer encoders, existing "null" output for nil pointers, omitempty, and struct-pointer recursion. It does not introduce an encoding format for unsupported types. Prepared with Codex assistance.

Related Tickets & Documents

Added/updated tests?

  • Yes. Seven focused cases cover unsupported pointer fields and slice elements, nil pointers, registered encoders, and preserved destination values.
  • No
  • I need help with writing tests

Run verifications and test

  • make verify is passing. It failed locally at lint: 14 findings (5 govet, 9 staticcheck) exactly match the untouched pinned upstream baseline under golangci-lint 2.15.0 and Go 1.27.2. The separately run make gosec failed with six G115 findings, all matching the upstream baseline in unchanged converter.go. make govulncheck exited successfully: no affected code vulnerabilities; one required-module vulnerability was reported as not called. These comparisons found no new findings, but do not make make verify pass.
  • make test is passing. On Ubuntu 24.04 with Go 1.27.2, the race-enabled suite passed with 92.7% statement coverage; go vet ./... and gofmt passed. An unchanged 15-case pointer matrix also passed, including three nil-output observations matching the pinned baseline.

The repository's Go 1.20/1.21 CI and golangci-lint 1.53 were not run here; nor were Windows or macOS checks.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant