Skip to content

Commit 913ef6e

Browse files
Extend: Ensure MIME string normalization (#756)
* ensure MIME string normalization in Extend() * use stdmime alias because mime is overloaded --------- Co-authored-by: Gabriel Vasile <gabriel.vasile@email.com>
1 parent 02cce61 commit 913ef6e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

mime.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package mimetype
22

33
import (
4-
"mime"
4+
stdmime "mime"
55
"slices"
66
"strings"
77

@@ -52,8 +52,8 @@ func (m *MIME) Parent() *MIME {
5252
func (m *MIME) Is(expectedMIME string) bool {
5353
// Parsing is needed because some detected MIME types contain parameters
5454
// that need to be stripped for the comparison.
55-
expectedMIME, _, _ = mime.ParseMediaType(expectedMIME)
56-
found, _, _ := mime.ParseMediaType(m.mime)
55+
expectedMIME, _, _ = stdmime.ParseMediaType(expectedMIME)
56+
found, _, _ := stdmime.ParseMediaType(m.mime)
5757

5858
if expectedMIME == found {
5959
return true
@@ -196,6 +196,7 @@ func (m *MIME) lookup(mime string) *MIME {
196196
// The sub-format will be detected if all the detectors in the parent chain return true.
197197
// The extension should include the leading dot, as in ".html".
198198
func (m *MIME) Extend(detector func(raw []byte, limit uint32) bool, mime, extension string, aliases ...string) {
199+
mime, _, _ = stdmime.ParseMediaType(mime)
199200
c := &MIME{
200201
mime: mime,
201202
extension: extension,

mimetype_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ func TestExtend(t *testing.T) {
748748
{"foo", ".foo", nil},
749749
{"bar", ".bar", root},
750750
{"baz", ".baz", zip},
751+
{" UperCaseWithWhiteSpace/a+B; key=val ", ".upercase", nil},
751752
}
752753

753754
for _, tt := range data {

0 commit comments

Comments
 (0)