From 5d17264c8ab8042042162f3b968557aabc4976b3 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 18 Aug 2026 11:47:38 +0200 Subject: test coverage for internal/accept --- internal/accept/accept.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'internal/accept/accept.go') diff --git a/internal/accept/accept.go b/internal/accept/accept.go index 5e35f45..5ed6e66 100644 --- a/internal/accept/accept.go +++ b/internal/accept/accept.go @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2026 Stefan Majewsky // SPDX-License-Identifier: Apache-2.0 -// TODO: unit test coverage (use the examples from RFC 9110) package accept import ( @@ -50,10 +49,16 @@ func ParseHeader(headers []string) Header { if err != nil { return none } + if _, ok := params["q"]; ok { + // malformed q-value that was not caught by the regex + return none + } opt := option{mediaType, params, 1.0} if weightStr != "" { opt.Weight, err = strconv.ParseFloat(weightStr, 64) if err != nil { + // defense in depth: unreachable because the regex match has + // extremely constrained grammar for `weightStr` return none } if opt.Weight > 1.0 { // this boundary is easier to express here than in the regex @@ -94,7 +99,7 @@ func (h Header) Negotiate(mediaTypes ...string) Option[string] { // we cannot choose from an empty set of options (this can only happen if the // caller gave us no or only malformed media types) - if len(mediaTypes) == 0 { + if len(offers) == 0 { return None[string]() } -- cgit v1.3.1