You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get a panic from html/template when I reference an untyped nil within a <script> tag. I bisected, which indicates https://golang.org/cl/95215 / 3cb54c8
What version of Go are you using (go version)?
$ go version
go version devel +542ea5ad91 Wed Apr 4 13:39:34 2018 -0700 darwin/amd64
$ go1.10 version
go version go1.10.1 darwin/amd64
Does this issue reproduce with the latest release?
The issue is present in tip. It is not present in go1.10.1.
What operating system and processor architecture are you using (go env)?
I use the html/template package, and one of my templates involves referencing a data field within a <script> tag. Usually I've set the field's value to some interesting structure I'm trying to pass to a js function. But sometimes it's an untyped nil stored in an interface{} field.
package main
import (
"html/template"
"os"
)
func main() {
data := struct {
A interface{}
B interface{}
}{
A: (*int)(nil),
B: nil,
}
template.Must(template.New("").Parse("<script>{{.A}}+{{.B}}</script>\n")).Execute(os.Stdout, data)
}
This is html/template-specific. With text/template, it generates:
<script><nil>+<no value></script>
as expected (in fact, better than expected).
robpike
changed the title
text/template: panic when calling function with untyped nil
html/template: panic when calling function with untyped nil
Apr 6, 2018
Thanks @odeke-em for the ping. I had seen this issue, but I had not realised it was directly connected to my other fix. I believe I know what the simple solution here is.
mvdan
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
May 8, 2018
I get a panic from html/template when I reference an untyped
nil
within a<script>
tag. I bisected, which indicates https://golang.org/cl/95215 / 3cb54c8What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
The issue is present in tip. It is not present in go1.10.1.
What operating system and processor architecture are you using (
go env
)?What did you do?
I use the html/template package, and one of my templates involves referencing a data field within a
<script>
tag. Usually I've set the field's value to some interesting structure I'm trying to pass to a js function. But sometimes it's an untypednil
stored in aninterface{}
field.Here's a play link, which runs successfully as expected: https://play.golang.org/p/e54VBAwyVTg
What did you expect to see?
I expected the field's value to be converted to a js-safe JSON representation.
(Weird that the untyped
nil
is written as""
rather thannull
, but it's been that way since at least Go 1.4.)What did you see instead?
The text was updated successfully, but these errors were encountered: