Skip to content

json/encoding: form feed encoded as \u000c instead of \f #64346

@ionous

Description

@ionous

Go version

go version go1.21.4 darwin/amd64

Reproducibility

  • Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/ionous/Library/Caches/go-build'
GOENV='/Users/ionous/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/ionous/Dev/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/ionous/Dev/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/ionous/Dev/GitHub/tell/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 x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/tv/ch5z1bgs21z1ft04rdk0kk400000gn/T/go-build41269137=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

formFeed:= "\f" 
fmt.Println(formFeed[0]== 0xc)
//
a, _ := json.MarshalIndent(formFeed, "", " ")
fmt.Println(string(a))
fmt.Println(strconv.Quote(formFeed))
fmt.Printf("%q", formFeed)
//
// prints: true, "\u000c", "\f", "\f"

https://play.golang.com/p/vbRfDhCj4DX

What did you expect to see?

i expected to see "\f" ( or maybe something in the documentation on what it escapes, and why. )

json supports escapes using: 'b', 'f', 'n', 'r', 't' -- but while appendString() in src/encoding/json/encode.go generates '\b', '\n', '\r', and '\t' -- it doesn't have handling for '\f'.

package fmt, and package strconv both generate "\f" when quoting 0xc.

What did you see instead?

marshal generates \u000c which -- while perfectly functional -- is unexpected

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions