Skip to content
Open
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
2 changes: 1 addition & 1 deletion filetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func IsMIME(buf []byte, mime string) bool {
if kind.MIME.Value == mime {
matcher := matchers.Matchers[kind]
result = matcher(buf) != types.Unknown
return false
return !result
}
return true
})
Expand Down
28 changes: 28 additions & 0 deletions filetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ func TestIsMIME(t *testing.T) {
}
}

func TestIsMIMESharedByTypes(t *testing.T) {
cases := []struct {
name string
buf []byte
mime string
}{
{"woff", []byte{0x77, 0x4F, 0x46, 0x46, 0x00, 0x01, 0x00, 0x00}, "application/font-woff"},
{"woff2", []byte{0x77, 0x4F, 0x46, 0x32, 0x00, 0x01, 0x00, 0x00}, "application/font-woff"},
{"ttf", []byte{0x00, 0x01, 0x00, 0x00, 0x00}, "application/font-sfnt"},
{"otf", []byte{0x4F, 0x54, 0x54, 0x4F, 0x00}, "application/font-sfnt"},
}

for _, test := range cases {
t.Run(test.name, func(t *testing.T) {
// The type registry has no guaranteed iteration order. Every
// matching type must work even when its sibling is visited first.
for i := 0; i < 100; i++ {
if !IsMIME(test.buf, test.mime) {
t.Fatalf("missing MIME match: %s", test.mime)
}
}
if IsMIME([]byte("not a font"), test.mime) {
t.Fatalf("unexpected MIME match: %s", test.mime)
}
})
}
}

func TestIsSupported(t *testing.T) {
cases := []struct {
ext string
Expand Down