-
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: panic when calling function with untyped nil #24717
Comments
This is html/template-specific. With text/template, it generates:
as expected (in fact, better than expected). |
/cc @mvdan |
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. |
@robpike the reason that text/template does a better job at discerning the two kinds of nil is because of https://go-review.googlesource.com/c/go/+/95215. I'm sure it was also behaving in a confusing way before that CL. |
Change https://golang.org/cl/109215 mentions this issue: |
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: