]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: add support for JavaScript modules
authorAndrew Bonventre <andybons@golang.org>
Sun, 5 May 2019 13:35:14 +0000 (09:35 -0400)
committerAndrew Bonventre <andybons@golang.org>
Mon, 6 May 2019 17:06:16 +0000 (17:06 +0000)
html/template does not properly treat JavaScript code as
JavaScript when using a <script> tag with "module" set as
the type attribute.

See also:
https://www.w3.org/TR/html5/semantics-scripting.html#element-attrdef-script-type and
https://html.spec.whatwg.org/multipage/scripting.html#the-script-element:module-script-2

Original change from tomut at https://golang.org/cl/135417

Fixes #31327

Change-Id: I6239be69cd7994990d091400664e4474124a98fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/175218
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/html/template/js.go
src/html/template/js_test.go

index 04c7c325dbd5091b36c56208f2ff01eb9f381820..7025c1cfaac5786c9071eec08ddf4c97431b40e9 100644 (file)
@@ -397,6 +397,7 @@ func isJSType(mimeType string) bool {
                "application/ld+json",
                "application/x-ecmascript",
                "application/x-javascript",
+               "module",
                "text/ecmascript",
                "text/javascript",
                "text/javascript1.0",
index 05fa105be02c705bb4d655209c8155412e6ef264..075adaafd3753c73d218ec8908e3d34fb0cb96dd 100644 (file)
@@ -344,6 +344,7 @@ func TestIsJsMimeType(t *testing.T) {
                {"text/javascript", true},
                {"application/json", true},
                {"application/ld+json", true},
+               {"module", true},
        }
 
        for _, test := range tests {