8000 net/http/httptest: should validate given URL · Issue #69750 · golang/go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

net/http/httptest: should validate given URL #69750

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

Closed
daisy1754 opened this issue Oct 2, 2024 · 2 comments
Closed

net/http/httptest: should validate given URL #69750

daisy1754 opened this issue Oct 2, 2024 · 2 comments

Comments

@daisy1754
Copy link

Go version

go version go1.22.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/myname/Library/Caches/go-build'
GOENV='/Users/myname/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/myname/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/myname/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/ny/tdk_b29j1dq560qnphb2s6g00000gn/T/go-build3187879218=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I had code like below in testing where generateRandomName function may return name that contains space. Test misses the URL encoding so it might produce URL like /v1/my-great-api?name=John Doe.

url := fmt.Sprintf("/v1/my-great-api?name=%s", generateRandomName())
r := httptest.NewRequest("GET", url, nil)

What did you see happen?

I got error message like this, which puzzled me for a while

panic: invalid NewRequest arguments; malformed HTTP version "Doe HTTP/1.0"

What did you expect to see?

While this is a user error, it would be helpful to get error message like

invalid URL "/v1/my-great-api?name=John Doe"

I'll be happy to send a PR to update validation logic, just wanted to make sure if this suggested fix makes sense first :)

@seankhliao
Copy link
Member

Duplicate of #26083

@seankhliao seankhliao marked this as a duplicate of #26083 Oct 2, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0