tpl: Fix race condition in text template baseof
authorCameron Moore <moorereason@gmail.com>
Sun, 17 Jan 2021 05:05:58 +0000 (23:05 -0600)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 22 Jan 2021 18:25:45 +0000 (19:25 +0100)
Copy most of the htmltemplate cloning to the textemplate implementation
in the same function.

tpl/tplimpl/template.go

index eb91ab837ac9cf3b8fe7d7d6f0f0e0335239379a..60e3b7df93febca85b307272d263451f5cffae17 100644 (file)
@@ -598,10 +598,16 @@ func (t *templateHandler) applyBaseTemplate(overlay, base templateInfo) (tpl.Tem
                        }
                }
 
-               templ, err = templ.Parse(overlay.template)
+               templ, err = texttemplate.Must(templ.Clone()).Parse(overlay.template)
                if err != nil {
                        return nil, overlay.errWithFileContext("parse failed", err)
                }
+
+               // The extra lookup is a workaround, see
+               // * https://github.com/golang/go/issues/16101
+               // * https://github.com/gohugoio/hugo/issues/2549
+               // templ = templ.Lookup(templ.Name())
+
                return templ, nil
        }