Skip to content

Commit

Permalink
Check for nil params to avoid a panic (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronf committed Oct 13, 2023
1 parent 05d3e0b commit c2276d4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var ErrInvalidParameterFormat = errors.New("invalid parameter format")
// ErrInvalidParameterValue is returned when a parameter key is invalid.
var ErrInvalidParameterValue = errors.New("invalid parameter value")

// ErrMissingParameters is returned when the Params structure is missing from the element.
var ErrMissingParameters = errors.New("missing parameters")

// NewParams creates a new ordered map.
func NewParams() *Params {
p := Params{}
Expand Down Expand Up @@ -74,6 +77,9 @@ func (p *Params) Names() []string {
// marshalSFV serializes as defined in
// https://httpwg.org/specs/rfc8941.html#ser-params.
func (p *Params) marshalSFV(b *strings.Builder) error {
if p == nil {
return ErrMissingParameters
}
for _, k := range p.names {
if err := b.WriteByte(';'); err != nil {
return err
Expand Down

0 comments on commit c2276d4

Please sign in to comment.