html/template: unexpected semantic differences compared to text/template #40075
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
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:Missing values passed explicitly to the html escaper format as
<nil>
instead of<no value>
:Given 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 text/template: zero template.Template no longer safe for use #11379.
TestMessageForExecuteEmpty shows a different error message:
TestIssue31810 fails (“check that a parenthesized first argument behaves properly”, for text/template: unintuitive behavior of parenthesized arguments in text/template and html/template #31810).
TestTemplateLookUp (for text/template: doesn't return template on lookup #10910, text/template: t.New() doesn't save entry in t.tmpl #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
The text was updated successfully, but these errors were encountered: