diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-08-18 11:47:38 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-08-18 11:47:38 +0200 |
| commit | 5d17264c8ab8042042162f3b968557aabc4976b3 (patch) | |
| tree | f08c2b2c790077aa79efd749b12c43a12982b608 /internal/accept/accept.go | |
| parent | 50ba9cfb04e257fafa3fdd566f9f70a1986339e8 (diff) | |
| download | go-gg-5d17264c8ab8042042162f3b968557aabc4976b3.tar.gz | |
test coverage for internal/accept
Diffstat (limited to 'internal/accept/accept.go')
| -rw-r--r-- | internal/accept/accept.go | 9 |
1 files changed, 7 insertions, 2 deletions
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 <majewsky@gmx.net> // 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]() } |
