Skip to content

text/template: JSEscape generates invalid JSON #37634

@sding3

Description

@sding3

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

$ go version
go version go1.14 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/shang/.cache/go-build"
GOENV="/home/shang/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="*.epic.com"
GONOSUMDB="*.epic.com"
GOOS="linux"
GOPATH="/home/shang/go"
GOPRIVATE="*.epic.com"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/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-build973203171=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Ran this code:

package main

import (
        "log"
        "os"
        "text/template"
)

func main() {
        const plate = `"{{ .Value | js}}"`

        type Vals struct {
                Value string
        }

        vals := &Vals{`=`}

        t := template.Must(template.New("plate").Parse(plate))

        err := t.Execute(os.Stdout, vals)
        if err != nil {
                log.Println("executing template:", err)
        }

}

What did you expect to see?

Expected to see "=", which is the behavior in go1.13.8

What did you see instead?

Insead see "\x3D".

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions