Skip to content

fix: map .midi to audio/midi, not to two media types joined by a space - #3227

Open
paolo-perrone wants to merge 1 commit into
replicate:mainfrom
paolo-perrone:fix/mime-midi-key
Open

paolo-perrone wants to merge 1 commit into
replicate:mainfrom
paolo-perrone:fix/mime-midi-key

Conversation

@paolo-perrone

Copy link
Copy Markdown

typeToExtension has the key "audio/midi audio/x-midi", which joins two media types with a space. init inverts the table, so TypeByExtension(".midi") returns that whole string. cog predict -i f=@song.midi then fails in pkg/predict/input.go when dataurl.New is given it as the media type, with dataurl: invalid mediatype.

TypeByExtension(".midi") // before: "audio/midi audio/x-midi"   after: "audio/midi"

This keeps one key, "audio/midi": ".midi", so ExtensionByType("audio/midi") still returns .midi. The other entries are only re-aligned by gofmt.

I added two tests to pkg/util/mime/mime_test.go: one for .midi in both directions, and one that every media type in the table, in both directions, parses with mime.ParseMediaType, so a key like this one cannot come back. I checked with a small standalone program that Go's parser rejects "audio/midi audio/x-midi" ("unexpected content after media subtype") and accepts "audio/midi". I could not run the repository's Go tests locally, so CI is the first real run of them.

AI assistance was used to find the bug and draft the change and tests. I reviewed every changed line.

Signed-off-by: paoloap <58889145+paoloap-py@users.noreply.github.com>
@paolo-perrone
paolo-perrone requested a review from a team as a code owner November 12, 2026 00:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant