Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
whitezhang opened this issue Oct 17, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@whitezhang
Copy link

commented Oct 17, 2016

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.

@whitezhang whitezhang changed the title Why + is parsed to space, but = is not in parseForm net: Why + is parsed to space, but = is not in parseForm Oct 17, 2016

@bradfitz

This comment has been minimized.

Copy link
Member

commented Oct 17, 2016

@bradfitz bradfitz closed this Oct 17, 2016

@go101

This comment has been minimized.

@mikioh mikioh changed the title net: Why + is parsed to space, but = is not in parseForm net/http: Why + is parsed to space, but = is not in parseForm Oct 17, 2016

@s7v7nislands

This comment has been minimized.

Copy link

commented Oct 18, 2016

package main

import (
"fmt"
"net/url"
)

func main() {
space := url.QueryEscape(" ")
fmt.Println(space)

}

On Mon, Oct 17, 2016 at 9:38 PM, whitezhang notifications@github.com
wrote:

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+CmludCBtYWluKCkKewoJcHJpbnRmKC
IzXG4iKTsKCXJldHVybiAwOwp9Cg==, 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+CmludCBtYWluKCkKewoJcHJpbnRmKC
IzXG4iKTsKCXJldHVybiAwOwp9Cg%3D%3D instead.

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


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#17479, or mute the thread
https://github.com/notifications/unsubscribe-auth/AANywqzKs5DQBH4LA3C4oXf_RYz115rKks5q03pOgaJpZM4KYoee
.

@golang golang locked and limited conversation to collaborators Oct 18, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.