Skip to content

affected/package: url.Parse #51358

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
xingcxb opened this issue Feb 25, 2022 · 4 comments
Closed

affected/package: url.Parse #51358

xingcxb opened this issue Feb 25, 2022 · 4 comments

Comments

@xingcxb
Copy link

xingcxb commented Feb 25, 2022

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

$ go version
go version go1.17.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/symbol/Library/Caches/go-build"
GOENV="/Users/symbol/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/symbol/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/symbol/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/Cellar/go/1.17.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.6/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f3/yy5sqg8107jfzkptg7b7b02r0000gn/T/go-build2818296805=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package testUtil

import (
	"fmt"
	"net/url"
	"testing"
)

func TestURL(t *testing.T) {
	fmt.Println(url.Parse("baidu.com:443"))
	fmt.Println(url.Parse("a360.com:443"))
	fmt.Println(url.Parse("360.com:443"))
}
=== RUN   TestURL
baidu.com:443 <nil>
a360.com:443 <nil>
<nil> parse "360.com:443": first path segment in URL cannot contain colon
--- PASS: TestURL (839.16s)
PASS

What did you expect to see?

The program to run normally.

What did you see instead?

@davecheney
Copy link
Contributor

A url must begin with a scheme, ie, https://, a scheme must begin with a letter, https://datatracker.ietf.org/doc/html/rfc3986#section-3.1. 360.com does not begin with a scheme so it is not a valid URL. The other two examples are also not valid URLs

package main

import (
	"fmt"
	"net/url"
)

func main() {
	x, _ := url.Parse("baidu.com:443")
	fmt.Println(x.Scheme) // prints baidu.com
}

I believe this is working as intended.

@mengzhuo
Copy link
Contributor

WAI Close #51358.

@xingcxb
Copy link
Author

xingcxb commented Feb 25, 2022

A url must begin with a scheme, ie, https://, a scheme must begin with a letter, https://datatracker.ietf.org/doc/html/rfc3986#section-3.1. 360.com does not begin with a scheme so it is not a valid URL. The other two examples are also not valid URLs

package main

import (
	"fmt"
	"net/url"
)

func main() {
	x, _ := url.Parse("baidu.com:443")
	fmt.Println(x.Scheme) // prints baidu.com
}

I believe this is working as intended.

A url must begin with a scheme, ie, https://, a scheme must begin with a letter, https://datatracker.ietf.org/doc/html/rfc3986#section-3.1. 360.com does not begin with a scheme so it is not a valid URL. The other two examples are also not valid URLs

package main

import (
	"fmt"
	"net/url"
)

func main() {
	x, _ := url.Parse("baidu.com:443")
	fmt.Println(x.Scheme) // prints baidu.com
}

I believe this is working as intended.

Sorry, you are right, I did not read the notes carefully 😮‍💨

@davecheney
Copy link
Contributor

It can be a bit confusing because the *url.URL object has a String method which does its best to print the components of the URL it just parsed — it looked like the url was parsed correctly, but that was unfortunately an ambiguity in the url spec with colons that early in the string.

@golang golang locked and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants