Skip to content

fix: decode named byte containers without panicking - #214

Open
DeviousCardi wants to merge 1 commit into
go-viper:mainfrom
DeviousCardi:fix/named-byte-string-conversion
Open

DeviousCardi wants to merge 1 commit into
go-viper:mainfrom
DeviousCardi:fix/named-byte-string-conversion

Conversation

@DeviousCardi

@DeviousCardi DeviousCardi commented Oct 18, 2026 •

Copy link
Copy Markdown

Weak string conversion currently panics for defined byte slice types and for slices or arrays with a defined uint8 element type. For example, type Octet uint8; var out string; WeakDecode([]Octet{'f', 'o', 'o'}, &out) panics instead of returning "foo". WeaklyTypedHook also panics on defined byte slices.

Use reflect.Value.Bytes for slices and Uint for array elements, matching the existing uint8-kind checks. Ordinary byte slices retain the existing conversion path without an extra buffer allocation. Add regression coverage for defined slice and element types, arrays, nil and empty containers, and binary bytes, plus both defined-slice cases in the hook tests.

Validation (Go 1.26.9, linux/amd64):

  • Both focused regressions reproduced interface conversion panics before the production changes.
  • go test -race -shuffle=on ./... passed.
  • go vet ./... passed.
  • git diff --check passed.

This bug was found independently; searches of existing issues and pull requests found no matching report or active fix.

Written by Codex.

Use reflection byte accessors instead of concrete byte type assertions in weak string conversions.

Assisted-by: Codex
@DeviousCardi
DeviousCardi marked this pull request as ready for review October 18, 2026 18:36
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.

1 participant