Skip to content

net/url: Parse and ParseRequestURI permissively accepts trailing colon after port #75223

@viktigpetterr

Description

@viktigpetterr

Go version

go version go1.25.0 darwin/arm6

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/viktigpetterr/go/bin'
GOCACHE='/Users/viktigpetterr/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/viktigpetterr/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/78/__zfw80925vgr6jyj1rw514m0000gn/T/go-build3038274493=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/viktigpetterr/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/viktigpetterr/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/opt/go/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/viktigpetterr/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I used url.Parse and url.ParseRequestURI to parse an URL with a trailing colon http://127.0.0.1:8080:.

https://go.dev/play/p/7KST83BAnsD

What did you see happen?

The URL was successfully parsed by both functions where I would expect them to return errors.

What did you expect to see?

I expected url.Parse and url.ParseRequestURI to return an error.

The docs state that net/url generally follows RFC 3986. To me, the trailing colon looks like a violation to the port specification

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions