html/template: unexpected semantic differences compared to text/template #40075
Labels
Milestone
Comments
Change https://golang.org/cl/241084 mentions this issue: |
gopherbot
pushed a commit
that referenced
this issue
Jul 14, 2020
Copy and adapt tests from text/template, to exercise more of html/template's copy. Various differences in behavior are flagged with NOTE comments or t.Skip and documented in #40075. Many of them are probably bugs. One clarifying test case added to both text/template and html/template. No changes to the package itself. Change-Id: Ifefad83d647db846040d24c2741a0244b00ade82 Reviewed-on: https://go-review.googlesource.com/c/go/+/241084 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Hi Go experts, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #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
The text was updated successfully, but these errors were encountered: