You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
yeah
What operating system and processor architecture are you using (go env)?
windows11 and amd64
go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\entropy_c\AppData\Local\go-build
set GOENV=C:\Users\entropy_c\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\Program Files\GoWorks\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\Program Files\GoWorks
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=D:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=D:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.6
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\Users\entropy_c\Desktop\codetest\gotest\test0314\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\ENTROP~1\AppData\Local\Temp\go-build1448317316=/tmp/go-build -gno-record-gcc-switches
GOROOT/bin/go version: go version go1.21.6 windows/amd64
GOROOT/bin/go tool compile -V: compile version go1.21.6
What did you do?
When using the ParseFiles method to parse a template, if the template name does not match the file name to be parsed, the "parse. Tree" of the template will be nil.
“ https://github.com/golang/go/blob/master/src/text/template/helper.go ”The "parseFiles" function in seems to have some unexpected situations when dealing with such scenarios.
tI := template.New("index")
tIndex, err := tI.ParseFiles("./template/index.html")
What did you expect to see?
The parse.Tree is not nil.
What did you see instead?
Here are some of the source code in helper. go. I think adding a "t=teml" can solve the problem.
var tmpl *Template
if t == nil {
t = New(name)
}
if name == t.Name() {
tmpl = t
} else {
tmpl = t.New(name)
t = tmpl // This code was added by me
}
_, err = tmpl.Parse(s)
if err != nil {
return nil, err
}
}
return t, nil
}
The text was updated successfully, but these errors were encountered:
seankhliao
changed the title
A bug in the 'parseFiles' function of' helper. go '
text/template: A bug in the 'parseFiles' function of' helper. go '
Mar 21, 2024
this is working as intended, note that you can pass multiple files to ParseFiles, and the current behavior is clearly documented:
Since the templates created by ParseFiles are named by the base names of the argument files
t should usually have the name of one of the (base) names of the files. If it does not, depending on t's contents before calling ParseFiles, t.Execute may fail.
the current template does not need to be entire and you may not necessarily want to override it.
What version of Go are you using (
go version
)?go 1.21.6
Does this issue reproduce with the latest release?
yeah
What operating system and processor architecture are you using (
go env
)?windows11 and amd64
go env
OutputWhat did you do?
When using the ParseFiles method to parse a template, if the template name does not match the file name to be parsed, the "parse. Tree" of the template will be nil.
“ https://github.com/golang/go/blob/master/src/text/template/helper.go ”The "parseFiles" function in seems to have some unexpected situations when dealing with such scenarios.
What did you expect to see?
The parse.Tree is not nil.
What did you see instead?
Here are some of the source code in helper. go. I think adding a "t=teml" can solve the problem.
}
The text was updated successfully, but these errors were encountered: