Open rsc opened 4 years ago
Change https://golang.org/cl/241084 mentions this issue: html/template: add tests from text/template
Hi Go experts,
is there any news on these behavioral differences?
We'd like to have missing values rendered as "<no value>
" in HTML templates, too...
@cfiderer My guess is that at this point adding <no value>
to HTML templates would break Hugo users quite badly. /cc @bep
In general I think it would make sense to track down why these differences exist before removing them.
I ported the text/template tests over to html/template and discovered some semantic differences between the two that I did not expect.
In html/template:
Missing values format as empty strings, while in text/template they format as
<no value>
. For example:{"map .NO", "{{.MSI.NO}}", "", tVal, true},
{"map .NO", "{{.MSI.NO}}", "", tVal, true}, // NOTE: in text/template
{"empty nil", "{{.Empty0}}", "", tVal, true},
{"empty nil", "{{.Empty0}}", "", tVal, true}, // NOTE: in text/template
and so on
Missing values passed explicitly to the html escaper format as
<nil>
instead of<no value>
:{{html .Empty0}}
, "<no value>", tVal, true},{{html .Empty0}}
, "<nil>", tVal, true}, // NOTE: "<no value>" in text/templateGiven an addressable struct field with a pointer-receiver String method, the String method is not used (in text/template it is):
Given an addressable struct field with a pointer-receiver Error method, the Error method is not used (in text/template it is):
TestExecuteOnNewTemplate crashes on all the cases from #11379.
TestMessageForExecuteEmpty shows a different error message:
TestIssue31810 fails (“check that a parenthesized first argument behaves properly”, for #31810).
TestTemplateLookUp (for #10910, #10926) fails. Lookup returns non-nil values for undefined templates.
Calling
Parse("")
does not overwrite the text of a previous template parse, as it does in text/template. See TestEmptyTemplate, specifically the last case in the table:The
<no value>
change looks like it may possibly be intentional. All the others look like bugs./cc @robpike