Skip to content

text/template: A terminator is erroneously detected in a field that starts with the same character as the right delimiter #52165

Closed
@mprahl

Description

@mprahl

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

$ go version                                          
go version go1.18 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/mprahl/.cache/go-build"
GOENV="/home/mprahl/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mprahl/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mprahl/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.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mprahl/git/go/src/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4256537278=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"os"
	"text/template"
)

func main() {
	tmpl, err := template.New("test").Delims("{{hub", "hub}}").Parse(`{{hub .Object.host hub}}`)
	if err != nil {
		panic(err)
	}

	err = tmpl.Execute(os.Stdout, struct{ Object map[string]string }{map[string]string{"host": "value"}})
	if err != nil {
		panic(err)
	}
}

What did you expect to see?

go run test.go
value

What did you see instead?

go run test.go
panic: template: test:1: unexpected <.> in operand

goroutine 1 [running]:
main.main()
        /tmp/test.go:11 +0x2ba
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions