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: Parse can't parse url like 10.88.237.69:4222 #21415

Closed
himulawang opened this issue Aug 12, 2017 · 2 comments
Closed

net/url: Parse can't parse url like 10.88.237.69:4222 #21415

himulawang opened this issue Aug 12, 2017 · 2 comments

Comments

@himulawang
Copy link

Please answer these questions before submitting your issue. Thanks!

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

1.8.3

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=d:\project
set GORACE=
set GOROOT=d:\SDK\go
set GOTOOLDIR=d:\SDK\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2

What did you do?

package main

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

func main() {
    addr := "10.88.237.69:4222"
    u, err := url.Parse(addr)
    if err != nil {
        fmt.Println(err.Error())
	os.Exit(1)
    }

    fmt.Println(u.Hostname(), u.Port())
}

A link on play.golang.org is best.
https://play.golang.org/p/AxIZvVA7fm

What did you expect to see?

err == nil
I think 10.88.237.69:4222 is a validate URL.

What did you see instead?

parse 10.88.237.69:4222: first path segment in URL cannot contain colon

@mvdan
Copy link
Member

mvdan commented Aug 12, 2017

This is not a valid URL. Valid URLs are like http://foo.bar or mailto:foo@bar.

You probably want https://golang.org/pkg/net/#SplitHostPort.

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

@gopherbot
Copy link

Change https://golang.org/cl/81436 mentions this issue: net/url: document Parse more

gopherbot pushed a commit that referenced this issue Dec 1, 2017
That Parse doesn't parse ("foo.com/path" or "foo.com:443/path") has
become something of a FAQ.

Updates #19779
Updates #21415
Updates #22955

Change-Id: Ib68efddb67f59b1374e8ed94effd4a326988dee7
Reviewed-on: https://go-review.googlesource.com/81436
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Dec 1, 2018
@mikioh mikioh changed the title url/ url.Parse can't parse url like 10.88.237.69:4222 net/url: Parse can't parse url like 10.88.237.69:4222 Feb 26, 2019
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

3 participants