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
Closed as not planned
Closed as not planned
@daisy1754

Description

@daisy1754

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 :)

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

      0