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
text/template: handling of nil
keyword
#58326
Comments
I agree that the behavior does not seem to match the documentation, but as the current behavior seems reasonable I think we should probably just adjust the documentation. CC @robpike |
Thanks @ianlancetaylor. Would you mind sharing your thoughts on how the current behavior seems reasonable? Or perhaps it is simply easier to adjust the docs rather than the logic for compatibility purposes? Personally, the handling of Stepping back a bit, the current documentation seems to suggest that Documentation snippets
Presently, the cases below seem non-trivial to justify, for example:
|
It seems reasonable to me because I'm not strongly opposed to changing the behavior, but I would not be at all surprised if we have to roll it back. Perhaps I should ask: what is your use case here? |
Appreciate the clarification!
I actually came across this behavior on accident, without a concrete use case to stake on. I was experimenting with The question in this issue appeared by isolating the behavior to a minimal reproducible example. 🙂 |
See my closing comment in #57773. Infeasible. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
These templates were evaluated to demonstrate how the argument
nil
is handled:{{nil}}
{{print nil}}
{{nil | print}}
Source (go.dev/play/p/ZUCywuoOq7E)
What did you expect to see?
According to the
text/template
docs,nil
is a valid standalone argument:Based on the above, these are expected to render:
{{nil}}
<no value>
(hownil
value renders){{print nil}}
<nil>
{{nil | print}}
<nil>
What did you see instead?
{{nil}}
"Template 0": at <nil>: nil is not a command
{{print nil}}
<nil>
{{nil | print}}
"Template 2": at <nil>: nil is not a command
If the observed behavior is actually correct/intentional, then should the docs be updated to reflect this?
The text was updated successfully, but these errors were encountered: