mime: make TypeByExtension follow Chrome+Firefox's precedence for webm->video and weba->audio

This CL updates TypeByExtension to correctly follow the precedence rules
that Chrome and Firefox use, whereby "webm" maps to "video/webm" and
"weba" maps to "audio/webm" per:

https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/net/base/mime_util.cc#169
https://github.com/mozilla-firefox/firefox/blob/main/uriloader/exthandler/nsExternalHelperAppService.cpp#L485

Thanks to Sean Liao for the above references.

Fixes #77701

Change-Id: I0e706c398aafc314034d7e1eccba9b37b8da00b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/747340
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
This commit is contained in:
Jakub Czyż
2026-02-19 23:41:07 +01:00
committed by Gopher Robot
parent f3755d9eba
commit 0bf3f64c6b
2 changed files with 4 additions and 2 deletions

View File

@@ -115,7 +115,8 @@ var builtinTypesLower = map[string]string{
".vtt": "text/vtt; charset=utf-8",
".wasm": "application/wasm",
".wav": "audio/wav",
".webm": "audio/webm",
".weba": "audio/webm",
".webm": "video/webm",
".webp": "image/webp",
".xbl": "text/xml; charset=utf-8",
".xbm": "image/x-xbitmap",

View File

@@ -245,7 +245,8 @@ func TestExtensionsByType2(t *testing.T) {
{typ: "text/vtt; charset=utf-8", want: []string{".vtt"}},
{typ: "application/wasm", want: []string{".wasm"}},
{typ: "audio/wav", want: []string{".wav"}},
{typ: "audio/webm", want: []string{".webm"}},
{typ: "audio/webm", want: []string{".weba"}},
{typ: "video/webm", want: []string{".webm"}},
{typ: "image/webp", want: []string{".webp"}},
{typ: "text/xml; charset=utf-8", want: []string{".xbl", ".xml", ".xsl"}},
{typ: "image/x-xbitmap", want: []string{".xbm"}},