-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
html/template: CL 274450 (in go1.16beta1) causes panic #43295
Comments
Can you tell us how we can recreate the problem ourselves? Thanks. It looks like somehow |
Try to write a reproducer according to your description, but fail to reproduce.
|
I’ll try to extract a reproduction case today |
Got a standalone reproduction case: package main
import (
"bytes"
"fmt"
"html/template"
)
type eepromVersion struct {
PieepromSHA256 string // pieeprom.sig
VL805SHA256 string // vl805.sig
}
type A struct {
EEPROM *eepromVersion
}
func main() {
s := `
{{ if .EEPROM }}
<tr>
<th>EEPROM<br>(SHA256)</th>
<td>{{ shortenSHA256 .EEPROM.PieepromSHA256 }}<br>{{ shortenSHA256 .EEPROM.VL805SHA256 }}</td>
</tr>
{{ end }}
`
e := eepromVersion{
"pieeprom.sig",
"vl805.sig",
}
a := A{
EEPROM: &e,
}
commonTmpls := template.New("root").Funcs(map[string]interface{}{
"shortenSHA256": func(hash string) string {
return hash
},
})
commonTmpls = template.Must(commonTmpls.New("header").Parse("head"))
overviewTmpl := template.Must(template.Must(commonTmpls.Clone()).New("overview").Parse(s))
out := &bytes.Buffer{}
if err := overviewTmpl.Execute(out, a); err != nil {
panic(err)
}
fmt.Println(out.String())
} Note that parsing the header template, and calling the shortenSHA256 function are both required to reproduce the bug. This also reproduces on linux/amd64. |
Change https://golang.org/cl/279432 mentions this issue: |
Change https://golang.org/cl/279492 mentions this issue: |
@stapelberg Thanks for the reproduction case. I think that https://golang.org/cl/279492 fixes the problem. It does fix your test case, at least. When you have time, give it a try on your original code. Thanks. |
Thanks for the quick fix! I just got a chance to test it in my original environment, and I hereby confirm that your https://golang.org/cl/279492 indeed does fix the problem for me. |
Closing, this appears to be fixed. Please let me know if I am mistaken. |
No, https://go-review.googlesource.com/c/go/+/279492/ has not yet been submitted. This isn’t fixed yet. |
Thanks, I was mistaken! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Reproduces with Go tip
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
As soon as I try to evaluate this template:
where
shortenSHA256
is defined as such:and EEPROM is of type
I get a panic at runtime:
The full panic is at https://gist.github.com/stapelberg/b804f2e0582b34b31ae069bfc36304ab in case it’s relevant.
I tracked this problem down to commit 5a4db10. Once I revert that commit, I no longer get the panic.
cc @ianlancetaylor
The text was updated successfully, but these errors were encountered: