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: does not preserve backslash from FormFile header when Filename contains Chinese #25888

Closed
lianzhao opened this issue Jun 14, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@lianzhao
Copy link

commented Jun 14, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.4 darwin/amd64

Does this issue reproduce with the latest release?

Have not tested yet

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lianzhao/work"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3x/fvc3fcrs5139r6g4k36sxl_40000gn/T/go-build489938146=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

Sent a form post request to upload a file with MSIE. Same issue with #15664
Except that my file name was in Chinese: C:\新建文件件\中文第二次测试.mp4

What did you expect to see?

I expected that consumeValue function in src/mime/mediatype.go returns 中文第二次测试.mp4

What did you see instead?

It returned C:新建文件件中文第二次测试.mp4
image

@agnivade

This comment has been minimized.

Copy link
Member

commented Jun 14, 2018

Can you try with 1.10.3 ?

Also, please post a self-contained example which can be reproduced, so that it is easy for us to investigate. Thanks.

@opennota

This comment has been minimized.

Copy link

commented Jun 15, 2018

The problem here is consumeValue assuming one-byte encoding (rune(v[i+1])):

if r == '\\' && i+1 < len(v) && !isTokenChar(rune(v[i+1])) {

@lianzhao

This comment has been minimized.

Copy link
Author

commented Jun 15, 2018

@agnivade This issue can be reproduced with go 1.10.3

go version

go version go1.10.3 darwin/amd64

go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lianzhao/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lianzhao/.gvm/pkgsets/go1.10.3/global"
GORACE=""
GOROOT="/Users/lianzhao/.gvm/gos/go1.10.3"
GOTMPDIR=""
GOTOOLDIR="/Users/lianzhao/.gvm/gos/go1.10.3/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3x/fvc3fcrs5139r6g4k36sxl_40000gn/T/go-build367734202=/tmp/go-build -gno-record-gcc-switches -fno-common"

Code to reproduce

package main

import (
	"log"
	"net/http"
)

func Upload(w http.ResponseWriter, r *http.Request) {
	_, header, _ := r.FormFile("file")
	log.Println(header.Filename)
}

func main() {
	http.Handle("/", http.FileServer(http.Dir("./static")))
	http.HandleFunc("/upload", Upload)
	http.ListenAndServe(":3001", nil)
}

issue-25888.zip

@agnivade agnivade changed the title net/http: Got incorrect Filename from FormFile header when Filename contains Chinese net/http: does not preserve backslash from FormFile header when Filename contains Chinese Jun 15, 2018

@agnivade agnivade added NeedsFix and removed WaitingForInfo labels Jun 15, 2018

@agnivade agnivade added this to the Go1.12 milestone Jun 15, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Jun 15, 2018

Thanks. Marking as 1.12 because 1.9 also has same behavior. /cc @bradfitz

@gopherbot

This comment has been minimized.

Copy link

commented Jun 19, 2018

Change https://golang.org/cl/119795 mentions this issue: mime: fixed consumeValue for unicode

@gopherbot gopherbot closed this in 3ff28f7 Sep 24, 2018

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