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/url: first path segment in URL cannot contain colon. #19297

Closed
shibingli opened this issue Feb 27, 2017 · 16 comments
Closed

net/url: first path segment in URL cannot contain colon. #19297

shibingli opened this issue Feb 27, 2017 · 16 comments

Comments

@shibingli
Copy link

Description:

No Scheme, and the address format is ”IP: Port“ Address parsing failed.

OS Ver:
Mac OSX 10.12.3

Go Ver:
1.8

Go ENV:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/shibingli/Develop/Go_Code/webconsole"
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/dy/lsbr_78131x3s9fjq15v8rg80000gn/T/go-build052845002=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

Code:

u, err := url.Parse("192.168.2.2:6688")
if nil != err {
       panic(err)
}
fmt.Println(u.Host, u.Port())

Error:

panic: parse 192.168.2.2:6688: first path segment in URL cannot contain colon

goroutine 1 [running]:
main.main()
	/Users/shibingli/Develop/Go_Code/webconsole/src/apibox.club/test/test.go:46 +0x138

Source:

https://github.com/golang/go/blob/release-branch.go1.8/src/net/url/url.go#L513

@shibingli shibingli changed the title net/url: Parse 192.168.2.2:6688 , first path segment in URL cannot contain colon. net/url: first path segment in URL cannot contain colon. Feb 27, 2017
@davecheney
Copy link
Contributor

davecheney commented Feb 27, 2017 via email

@mattn
Copy link
Member

mattn commented Feb 27, 2017

@davecheney

package main

import (
	"fmt"
	"net/url"
)

func main() {
	fmt.Println(url.Parse("www.google.com:443"))
	fmt.Println(url.Parse("192.168.1.2:443"))
}
www.google.com:443 <nil>
<nil> parse 192.168.1.2:443: first path segment in URL cannot contain colon

I don't make sure but it seems fail when the host is IP.

@shibingli
Copy link
Author

shibingli commented Feb 27, 2017

@mattn I think you're right。
@davecheney www.google.com: 443 and 192.168.1.2:443 should be the same.

Golang 1.7 version can do so.

@mattn
Copy link
Member

mattn commented Feb 27, 2017

https://github.com/golang/go/blob/release-branch.go1.8/src/net/url/url.go#L500

www.google.com is treated as scheme at this line.

@mattn
Copy link
Member

mattn commented Feb 27, 2017

In my opinion, this is not a bug because rfc3986 allow to use dot in scheme.

@mattn
Copy link
Member

mattn commented Feb 27, 2017

@shibingli if you want to parse such string, please use url.Parse("//192.168.1.2:443") instead.

@shibingli
Copy link
Author

@mattn Okay, I've done that. But I think it is normal to do that.

@dsnet
Copy link
Member

dsnet commented Feb 27, 2017

Closing as working-as-intended. It could be documented better. That is #18824.
But @mattn is right. The correct way is //192.168.1.2:44. Read #18824 for details.

@dsnet dsnet closed this as completed Feb 27, 2017
@shibingli
Copy link
Author

@dsnet Thanks.

eikaas added a commit to eikaas/kite that referenced this issue Jun 23, 2017
A change made to the net/url library in go 1.8 causes a panic when
starting kontrol:

panic: parse 127.0.0.1:4001: first path segment in URL cannot contain colon

This is caused by the fact that net/url no longer considers
"127.0.0.1:4001" a valid URL because the specification allows for dots
in the schema-part of the URL.

* golang/go#19297
@henry3695
Copy link

u, err := url.Parse("//192.168.2.2:6688")
if nil != err {
panic(err)
}
fmt.Println(u.Host, u.Port())

very ok

@kirichenko
Copy link

ERROR: failed to parse http://ddmwebrevo.digdes.com/#/document/ca061121-8679-4afb-bf96-5aefdcac2dbf : parse http://ddmwebrevo.digdes.com/: first path segment in URL cannot contain colon

@mattn
Copy link
Member

mattn commented Sep 19, 2017

@kirichenko Could you please show your minimal code to reproduce?

@kirichenko
Copy link

I'm sorry. There was a typo in URL (space in the begining).

dmjio added a commit to dmjio/nixpkgs that referenced this issue Oct 6, 2017
Go will fail to parse this otherwise.
golang/go#19297
@edwardstudy
Copy link

edwardstudy commented Jan 5, 2018

Hi. I met the error: parse 127.0.0.1:65085/auth/v1.0/: first path segment in URL cannot contain colon. But 'localhost::65085/auth/v1.0/' was work.

@smileboywtu
Copy link

smileboywtu commented Mar 5, 2018

first path segment in URL cannot contain colon

here is the url:
http://zhidao.baidu.com/special/view?id=a9105a24626975510000&preview=1

is there something wrong

@bradfitz
Copy link
Contributor

bradfitz commented Mar 5, 2018

This is a closed issue. Closed issues aren't tracked.

For questions about Go, see https://golang.org/wiki/Questions.

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

No branches or pull requests

9 participants