Skip to content

Commit d25beae

Browse files
committed
fix(options): reject nil annotation key in WithAnnotation
1 parent a41654b commit d25beae

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ func WithClientIPResolver(resolver ClientIPResolver) interface {
321321
// packages that use route annotation.
322322
func WithAnnotation(key, value any) RouteOption {
323323
return optionFunc(func(s sealedOption) error {
324+
if key == nil {
325+
return fmt.Errorf("%w: annotation key is nil", ErrInvalidConfig)
326+
}
324327
if !reflect.TypeOf(key).Comparable() {
325328
return fmt.Errorf("%w: annotation key is not comparable", ErrInvalidConfig)
326329
}

options_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ func TestWithAnnotation_Invalid(t *testing.T) {
762762
f, err := NewRouter()
763763
require.NoError(t, err)
764764
assert.ErrorIs(t, onlyError(f.Add(MethodGet, "/foo/{bar}", emptyHandler, WithAnnotation(nonComparableKey, nil))), ErrInvalidConfig)
765+
assert.ErrorIs(t, onlyError(f.Add(MethodGet, "/foo/{bar}", emptyHandler, WithAnnotation(nil, "value"))), ErrInvalidConfig)
765766
}
766767

767768
func TestWithQueryMatcher(t *testing.T) {

0 commit comments

Comments
 (0)