Skip to content

net/http: Why + is parsed to space, but = is not in parseForm #17479

Closed
@whitezhang

Description

@whitezhang

Please answer these questions before submitting your issue. Thanks!

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

1.6.1

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

What did you do?

I post a form to the golang backend. And In my nginx log, the code is I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBtYWluKCkKewoJcHJpbnRmKCIzXG4iKTsKCXJldHVybiAwOwp9Cg==, where there is a +.

And I parse the form using the following code:

r.ParseForm()
rawCode, _ := url.QueryUnescape(r.PostFormValue("code"))
pid := r.PostFormValue("pid")
log.Println(rawCode)
code, err := base64.RawURLEncoding.DecodeString(rawCode)

But when I print the code, I got I2luY2x1ZGUgPHN0ZGlvLmg CmludCBtYWluKCkKewoJcHJpbnRmKCIzXG4iKTsKCXJldHVybiAwOwp9Cg==, where the + is replaced by space

I also tried rawCode := url.QueryEscape(r.PostFormValue("code")), but I got I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBtYWluKCkKewoJcHJpbnRmKCIzXG4iKTsKCXJldHVybiAwOwp9Cg%3D%3D instead.

Is there a bug in golang?? Because here should be I2luY2x1ZGUgPHN0ZGlvLmg CmludCBtYWluKCkKewoJcHJpbnRmKCIzXG4iKTsKCXJldHVybiAwOwp9Cg%3D%3D if parsed or ``I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBtYWluKCkKewoJcHJpbnRmKCIzXG4iKTsKCXJldHVybiAwOwp9Cg==` if not parsed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions