Skip to content
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: Tree is only updated after Execute is called #43064

Open
silversquirl opened this issue Dec 8, 2020 · 7 comments · May be fixed by #47972
Open

html/template: Tree is only updated after Execute is called #43064

silversquirl opened this issue Dec 8, 2020 · 7 comments · May be fixed by #47972
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@silversquirl
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.15.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vktec/.cache/go-build"
GOENV="/home/vktec/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/vktec/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/vktec/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build234409553=/tmp/go-build -gno-record-gcc-switches"

What did you do?

tmpl := template.Must(template.New("").Parse(`{{.}}`))
fmt.Println(tmpl.Tree.Root)
tmpl.Execute(ioutil.Discard, "")
fmt.Println(tmpl.Tree.Root)

https://play.golang.org/p/Tt61uh_jIRf

What did you expect to see?

Before Execute is called, the Tree should already have been "updated to be HTML-safe", as implied by the documentation for that field:

The underlying template's parse tree, updated to be HTML-safe.

What did you see instead?

The Tree is only updated after Execute is called.

@silversquirl
Copy link
Author

It's possible this is intended. If so, I'd like to request the documentation be updated to make that clearer, and the internal escape method be made public so the tree can be updated without having to call Execute.

@toothrot toothrot added this to the Backlog milestone Dec 8, 2020
@toothrot
Copy link
Contributor

toothrot commented Dec 8, 2020

/cc @empijei

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 10, 2020
@empijei
Copy link
Contributor

empijei commented Dec 16, 2020

This is intended as escaping needs to be lazily evaluated.

We should probably update the doc to reflect this behavior. Would you like to try and send a CL to do so?

Partially related: #39807

@empijei empijei added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 16, 2020
@Windsooon
Copy link

Maybe we can delete that line of comment or update the comment like this:

type Template struct {

	// After running Execute() or ExecuteTemplate(), the underlying template's parse tree, updated to be HTML-safe.
	Tree *parse.Tree
	// contains filtered or unexported fields
}

/cc @vktec @empijei

@empijei
Copy link
Contributor

empijei commented Aug 2, 2021

What about The underlying template's parse tree, updated to be HTML-safe after the first execution.

@Windsooon
Copy link

@empijei Your comment would be much better, which is more concise and easier to understand. 👍

Windsooon added a commit to Windsooon/go that referenced this issue Aug 26, 2021
The current comment "The underlying template's parse tree, updated to be HTML-safe."
at https://pkg.go.dev/html/template#Template is not correct

Fixes golang#43064
@gopherbot
Copy link

Change https://golang.org/cl/345030 mentions this issue: html/template: Tree is only updated after Execute() is called

Windsooon added a commit to Windsooon/go that referenced this issue Sep 13, 2021
Windsooon added a commit to Windsooon/go that referenced this issue Sep 13, 2021
The underlying template's parse tree at html/template#Template, updated to be HTML-safe after the first execution.

Fixes golang#43064
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants