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
Closed

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

whitezhang opened this issue Oct 17, 2016 · 3 comments

Comments

@whitezhang
Copy link

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
Copy link
Contributor

For questions, see https://golang.org/wiki/Questions

@go101
Copy link

go101 commented Oct 17, 2016

@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
Copy link

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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants