Skip to content

html: html.UnescapeString("(&#9)") does not decode single character number #66058

@yffrankwang

Description

@yffrankwang

Go version

go version go1.21.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ubuntu/.cache/go-build'
GOENV='/home/ubuntu/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ubuntu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ubuntu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/gol.21.4'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/gol.21.4/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4093406638=/tmp/go-build -gno-record-gcc-switches'

What did you do?

the html.UnescapeString() function does not decode one character number correctly.

package main

import (
	"fmt"
	"html"
)

func main() {
	fmt.Println(html.UnescapeString("(&#9)"))
}

https://go.dev/play/p/kCEC5INrCNt

What did you see happen?

output:

(&#9)

I think the "No characters matched." check logic of function html.unescapeEntity() is incorrect.

https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/html/escape.go;l=107

What did you expect to see?

want:

(\t)

Edge/Chrome/Firefox displays the following html as (  ).

<pre>(&#9)</pre>

https://jsfiddle.net/Lkm6jy3c/

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions