Skip to content

Commit 52f68ef

Browse files
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 <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
1 parent 1247354 commit 52f68ef

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

doc/go1.19.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,22 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
216216
</dd>
217217
</dl><!-- io -->
218218

219+
<dl id="mime"><dt><a href="/pkg/mime/">mime</a></dt>
220+
<dd>
221+
<p><!-- CL 406894 -->
222+
On Windows only, the mime package now ignores a registry entry
223+
recording that the extension <code>.js</code> should have MIME
224+
type <code>text/plain</code>. This is a common unintentional
225+
misconfiguration on Windows systems. The effect is
226+
that <code>.js</code> will have the default MIME
227+
type <code>text/javascript; charset=utf-8</code>.
228+
Applications that expect <code>text/plain</code> on Windows must
229+
now explicitly call
230+
<a href="/pkg/mime#AddExtensionType"><code>AddExtensionType</code></a>.
231+
</p>
232+
</dd>
233+
</dl>
234+
219235
<dl id="net"><dt><a href="/pkg/net/">net</a></dt>
220236
<dd>
221237
<p><!-- CL 386016 -->

src/mime/type_windows.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ func initMimeWindows() {
3030
if err != nil {
3131
continue
3232
}
33+
34+
// There is a long-standing problem on Windows: the
35+
// registry sometimes records that the ".js" extension
36+
// should be "text/plain". See issue #32350. While
37+
// normally local configuration should override
38+
// defaults, this problem is common enough that we
39+
// handle it here by ignoring that registry setting.
40+
if name == ".js" && (v == "text/plain" || v == "text/plain; charset=utf-8") {
41+
continue
42+
}
43+
3344
setExtensionType(name, v)
3445
}
3546
}

0 commit comments

Comments
 (0)