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: {{range}} branches end in different contexts #54999

Closed
timdadd opened this issue Sep 10, 2022 · 2 comments
Closed

html/template: {{range}} branches end in different contexts #54999

timdadd opened this issue Sep 10, 2022 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@timdadd
Copy link

timdadd commented Sep 10, 2022

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

$ go version

Does this issue reproduce with the latest release? Yes

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

GO playground & UBUNTU

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tim/.cache/go-build"
GOENV="/home/tim/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tim/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tim/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/tim/go/src/oc/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3443675751=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wrote a RANGE statement in Javascript part of HTML template and received a CONTEXT error.
I fixed this by manually inserting the first line that would be generated by the RANGE statement before running the RANGE statement
More details at https://stackoverflow.com/questions/73675601/go-1-19-error-executing-template-range-branches-end-in-different-contexts
GO Playground Link https://go.dev/play/p/RELjQ71DT0O. Just comment out or delete the line before the RANGE statement to see the problem

What did you expect to see?

No CONTEXT error

What did you see instead?

A CONTEXT error

@seankhliao seankhliao changed the title template/html html/template: {{range}} branches end in different contexts Sep 10, 2022
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 10, 2022
@seankhliao
Copy link
Member

It's not liking

// js comment
{{- directive with strip leading space }}

as what comes after might end up on the same line as the js comment, making it unclear what sort of escaping to do.

cc @empijei

@seankhliao seankhliao added this to the Unplanned milestone Sep 10, 2022
@timdadd
Copy link
Author

timdadd commented Sep 11, 2022

Thanks for the explanation but I would have expected the code to be generated with the first line of the range being made part of the comment. In this scenario, the code wouldn't be doing the right thing, but automatically adding stuff to comments is not necessarily a bad thing, I auto generate comments from templates in many places and also use range to get the first thing from a map and then break. So it does seem to me that I could easily have this scenario to build a comment. The context error completely threw me on this.

@timdadd timdadd closed this as completed Sep 11, 2022
@golang golang locked and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants