From 52f68efa45a34e60e8fc5a2ad5fc124a865ac2a4 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 17 May 2022 12:28:28 -0700 Subject: [PATCH] mime: ignore .js => text/plain in Windows registry This seems to be a common registry misconfiguration on Windows. Fixes #32350 Change-Id: I68c617c42a6e72948e2acdf335ff8e7df569432d Reviewed-on: https://go-review.googlesource.com/c/go/+/406894 Reviewed-by: Michael Knyszek TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Reviewed-by: Damien Neil --- doc/go1.19.html | 16 ++++++++++++++++ src/mime/type_windows.go | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/doc/go1.19.html b/doc/go1.19.html index a83a916c72..c809e10551 100644 --- a/doc/go1.19.html +++ b/doc/go1.19.html @@ -216,6 +216,22 @@ Do not send CLs removing the interior tags from such phrases. +
mime
+
+

+ On Windows only, the mime package now ignores a registry entry + recording that the extension .js should have MIME + type text/plain. This is a common unintentional + misconfiguration on Windows systems. The effect is + that .js will have the default MIME + type text/javascript; charset=utf-8. + Applications that expect text/plain on Windows must + now explicitly call + AddExtensionType. +

+
+
+
net

diff --git a/src/mime/type_windows.go b/src/mime/type_windows.go index cee9c9db04..93802141c5 100644 --- a/src/mime/type_windows.go +++ b/src/mime/type_windows.go @@ -30,6 +30,17 @@ func initMimeWindows() { if err != nil { continue } + + // There is a long-standing problem on Windows: the + // registry sometimes records that the ".js" extension + // should be "text/plain". See issue #32350. While + // normally local configuration should override + // defaults, this problem is common enough that we + // handle it here by ignoring that registry setting. + if name == ".js" && (v == "text/plain" || v == "text/plain; charset=utf-8") { + continue + } + setExtensionType(name, v) } }