golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.07k stars 17.68k forks source link

text/template: quoted "*/" within a /*...*/ comment terminates the comment #70366

Open clearcodecn opened 4 hours ago

clearcodecn commented 4 hours ago

Parsing this string with text/template gives an error:

{{/*  print "*/" */}}                 -> error: "comment ends before closing delimiter"

Go version

go version go1.23.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/zmj/Library/Caches/go-build'
GOENV='/Users/zmj/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/zmj/go/pkg/mod'
GONOPROXY='git.dustess.com'
GONOSUMDB='git.dustess.com'
GOOS='darwin'
GOPATH='/Users/zmj/go'
GOPRIVATE='git.dustess.com'
GOPROXY='https://goproxy.io'
GOROOT='/Users/zmj/.gvm/gos/go1.23.2'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/zmj/.gvm/gos/go1.23.2/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/zmj/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='/usr/bin/cc'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/zmj/Desktop/projects/sfshare/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/2d/_qd9vb7n5yqfhxgx57llw8l40000gn/T/go-build685601311=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

https://go.dev/play/p/-jIq4rJbRfG

What did you see happen?

parse template failed:  template: :2: comment ends before closing delimiter

What did you expect to see?

except no error

gabyhelp commented 4 hours ago

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

adonovan commented 1 hour ago

Is this actually a bug? The Go scanner works in the exact same way: https://go.dev/play/p/PCwzdxqPyD9

package main

func main() {
    /* println("*/") */                       error: newline in string
}