Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions component_identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ func toComponentIdentifiers(identifiers []string) ([]*componentIdentifier, error
}

func newComponentIdentifier(item httpsfv.Item) (*componentIdentifier, error) {
// ok if panics
name := strings.ToLower(item.Value.(string)) //nolint: forcetypeassert
name, ok := item.Value.(string)
if !ok {
return nil, fmt.Errorf("%w: component name must be a string", ErrInvalidComponentIdentifier)
}

canonicalizer, err := canonicalizerFor(name)
canonicalizer, err := canonicalizerFor(strings.ToLower(name))
if err != nil {
return nil, err
}
Expand Down
10 changes: 10 additions & 0 deletions component_identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ func TestNewComponentIdentifier(t *testing.T) {
item httpsfv.Item
assert func(t *testing.T, ci *componentIdentifier, err error)
}{
{
uc: "non-string component name",
item: httpsfv.NewItem(int64(42)),
assert: func(t *testing.T, ci *componentIdentifier, err error) {
t.Helper()

require.ErrorIs(t, err, ErrInvalidComponentIdentifier)
assert.Nil(t, ci)
},
},
{
uc: "invalid",
item: httpsfv.NewItem("@foo"),
Expand Down
2 changes: 1 addition & 1 deletion httpsig.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
// ErrUnsupportedComponentIdentifier indicates that a covered component identifier is unsupported.
ErrUnsupportedComponentIdentifier = errors.New("unsupported component identifier")

// ErrInvalidComponentIdentifier indicates malformed or invalid parameters on a component identifier.
// ErrInvalidComponentIdentifier indicates a malformed component identifier or invalid component parameters.
ErrInvalidComponentIdentifier = errors.New("invalid component identifier")

// ErrCanonicalization indicates that a covered HTTP message component could not be canonicalized.
Expand Down
Loading