Keyboard Shortcuts

File
u :up to issue
m :publish + mail comments
M :edit review message
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
<Enter> :respond to / edit current comment
d :mark current comment as done
Issue
u :up to list of issues
m :publish + mail comments
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
# : close issue
Comment/message editing
<Ctrl> + s or <Ctrl> + Enter :save comment
<Esc> :cancel edit
Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(138)
Issues Repositories Search
Open Issues | Closed Issues | All Issues | Sign in with your Google Account to create issues and add comments

Issue 7038045: code review 7038045: net: SplitHostPort: adjust error message for missing po...

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years ago by knieriem
Modified:
12 years, 11 months ago
Reviewers:
rsc , mikio
CC:
dave_cheney.net, rsc, mikio, golang-dev
Visibility:
Public.
net: SplitHostPort: adjust error message for missing port in IPv6 addresses An hostport of "[::1]" now results in the same error message "missing port in address" as the hostport value "127.0.0.1", so SplitHostPort won't complain about "too many colons in address" anymore for an IPv6 address missing a port. Added tests checking the error values. Fixes issue 4526.

Patch Set 1 #

Patch Set 2 : diff -r 88ae367d61aa https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 88ae367d61aa https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 4 : diff -r 08a1396e9aa7 https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r 7359dad2971d https://go.googlecode.com/hg/ #

Created: 13 years ago
Download [raw] [tar.bz2]
Unified diffs Side-by-side diffs Delta from patch set Stats (+82 lines, -11 lines) Patch
M src/pkg/net/ip_test.go View 1 2 3 4 2 chunks +32 lines, -0 lines 0 comments Download
M src/pkg/net/ipsock.go View 1 2 3 4 1 chunk +50 lines, -11 lines 0 comments Download
Total messages: 13
|
knieriem
Hello golang-dev@googlegroups.com (cc: mikioh.mikioh@gmail.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years ago (2012年12月31日 20:41:07 UTC) #1
Hello golang-dev@googlegroups.com (cc: mikioh.mikioh@gmail.com),
I'd like you to review this change to
https://go.googlecode.com/hg/ 
Sign in to reply to this message.
dave_cheney.net
What happens with these test cases 0.0.0.0:0 :0 127.0.0.1: www.google.com: On 1 Jan 2013 10:27, ...
13 years ago (2012年12月31日 23:34:48 UTC) #2
What happens with these test cases
0.0.0.0:0
:0
127.0.0.1:
www.google.com:
On 1 Jan 2013 10:27, <mt4swm@googlemail.com> wrote:
> Reviewers: golang-dev_googlegroups.com,
>
> Message:
> Hello golang-dev@googlegroups.com (cc: mikioh.mikioh@gmail.com),
>
> I'd like you to review this change to
> https://go.googlecode.com/hg/
>
>
> Description:
> net: SplitHostPort: adjust error message for missing port in IPv6
> addresses
>
> An hostport of "[::1]" now results in the same error message
> "missing port in address" as the hostport value "127.0.0.1",
> so SplitHostPort won't complain about "too many colons
> in address" anymore for an IPv6 address missing a port.
>
> Added tests checking the error values.
>
> Fixes issue 4526.
>
> Please review this at
https://codereview.appspot.**com/7038045/<https://codereview.appspot.com/7038...
>
> Affected files:
> M src/pkg/net/ip_test.go
> M src/pkg/net/ipsock.go
>
>
> Index: src/pkg/net/ip_test.go
> ==============================**==============================**=======
> --- a/src/pkg/net/ip_test.go
> +++ b/src/pkg/net/ip_test.go
> @@ -271,12 +271,32 @@
> {"google.com", "https%foo", "google.com:https%foo"}, // Go 1.0
> behavior
> }
>
> +var splitfailuretests = []struct {
> + HostPort string
> + Err string
> +}{
> + {"www.google.com", "missing port in address"},
> + {"127.0.0.1", "missing port in address"},
> + {"[::1]", "missing port in address"},
> + {"::1", "too many colons in address"},
> +}
> +
> func TestSplitHostPort(t *testing.T) {
> for _, tt := range splitjointests {
> if host, port, err := SplitHostPort(tt.Join); host !=
> tt.Host || port != tt.Port || err != nil {
> t.Errorf("SplitHostPort(%q) = %q, %q, %v; want %q,
> %q, nil", tt.Join, host, port, err, tt.Host, tt.Port)
> }
> }
> + for _, tt := range splitfailuretests {
> + if _, _, err := SplitHostPort(tt.HostPort); err == nil {
> + t.Errorf("SplitHostPort(%q) should have failed",
> tt.HostPort)
> + } else {
> + e := err.(*AddrError)
> + if e.Err != tt.Err {
> + t.Errorf("SplitHostPort(%q) = _, _, %q;
> want %q", tt.HostPort, e.Err, tt.Err)
> + }
> + }
> + }
> }
>
> func TestJoinHostPort(t *testing.T) {
> Index: src/pkg/net/ipsock.go
> ==============================**==============================**=======
> --- a/src/pkg/net/ipsock.go
> +++ b/src/pkg/net/ipsock.go
> @@ -85,9 +85,12 @@
> }
> host, port = hostport[:i], hostport[i+1:]
> // Can put brackets around host ...
> - if len(host) > 0 && host[0] == '[' && host[len(host)-1] == ']' {
> + switch {
> + case insideBrackets(host):
> host = host[1 : len(host)-1]
> - } else {
> + case insideBrackets(hostport):
> + err = &AddrError{"missing port in address", hostport}
> + default:
> // ... but if there are no brackets, no colons.
> if byteIndex(host, ':') >= 0 {
> err = &AddrError{"too many colons in address",
> hostport}
> @@ -97,6 +100,10 @@
> return
> }
>
> +func insideBrackets(s string) bool {
> + return len(s) > 0 && s[0] == '[' && s[len(s)-1] == ']'
> +}
> +
> // JoinHostPort combines host and port into a network address
> // of the form "host:port" or, if host contains a colon, "[host]:port".
> func JoinHostPort(host, port string) string {
>
>
>
Sign in to reply to this message.
knieriem
On Tue, 1 Jan 2013 10:34:47 +1100 Dave Cheney <dave@cheney.net> wrote: > What happens with ...
13 years ago (2013年01月02日 02:06:07 UTC) #3
On Tue, 1 Jan 2013 10:34:47 +1100
Dave Cheney <dave@cheney.net> wrote:
> What happens with these test cases
> 
> 0.0.0.0:0
> :0
> 127.0.0.1:
> www.google.com:
These hostport values all pass SplitHostPort without
an error (same as in the past).
The last two values (those with the colon at the end)
should probably also yield a "missing port in address"
error. I can adjust SplitHostPort accordingly if you like.
The first value is matched by the test case for
127.0.0.1:1234, I suppose.
For the second value -- ":0" with a missing host part --
I could add a test to splitjointests that checks that empty
host parts actually are regarded as valid (which is
SplitHostPort's current behaviour, and has a usage in
address arguments to Listen calls).
	+	{"", "0", ":0"},
Sign in to reply to this message.
rsc
https://codereview.appspot.com/7038045/diff/2002/src/pkg/net/ip_test.go File src/pkg/net/ip_test.go (right): https://codereview.appspot.com/7038045/diff/2002/src/pkg/net/ip_test.go#newcode271 src/pkg/net/ip_test.go:271: {"google.com", "https%foo", "google.com:https%foo"}, // Go 1.0 behavior Please add ...
13 years ago (2013年01月07日 04:55:41 UTC) #4
https://codereview.appspot.com/7038045/diff/2002/src/pkg/net/ip_test.go
File src/pkg/net/ip_test.go (right):
https://codereview.appspot.com/7038045/diff/2002/src/pkg/net/ip_test.go#newco...
src/pkg/net/ip_test.go:271: {"google.com", "https%foo", "google.com:https%foo"},
// Go 1.0 behavior
Please add Dave's test cases here. You can put // Go 1.0 behavior
for the empty string ports if you like. The goal is to avoid regressions.
Please also add
{"[foo]:[bar]baz", "foo", "[bar]baz"}
https://codereview.appspot.com/7038045/diff/2002/src/pkg/net/ip_test.go#newco...
src/pkg/net/ip_test.go:281: {"::1", "too many colons in address"},
Please add
{"[foo:bar]", "missing port in address"}
{"[foo:bar]baz", "missing port in address"}
{"[foo]:[bar]:baz", "too many colons in address"},
here. I think you will find that the last two cases need work.
We should probably reject them, and that will be a Go 1.0 regression,
but one that I am willing to treat as a bug fix.
The docs are clear that the allowed forms are host:port and [host]:port.
I think that means that if the string begins with [, then scanning forward 
we have to find a ], and the ] must be followed by a :, which is the separator.
There must be no colons after the separator.
If the string does not begin with [, then the separator is the last :.
Sign in to reply to this message.
knieriem
I've prepared a program in the Go Playground that contains all the changes: http://play.golang.org/p/9Im0PcQf-F It ...
13 years ago (2013年01月08日 13:58:40 UTC) #5
I've prepared a program in the Go Playground that
contains all the changes:
	http://play.golang.org/p/9Im0PcQf-F
It tells how the behaviour of the new SplitHostPort function
will differ from the one in the Playground's Go version (1.0.3).
Test cases are prefixed by "==" and "!=" accordingly.
I've added another test case, "[foo]bar:baz", which didn't
fail in Go 1.0, but now would fail with the "missing port" error.
I wonder how the following cases should be handled:
	foo[bar]:baz
	fo[bar]o:baz
With the present patch, and in Go 1.0, these values wouldn't yield
an error.
I'll push the new patch to codereview a few hours later.
Sign in to reply to this message.
knieriem
Hello dave@cheney.net, rsc@golang.org (cc: golang-dev@googlegroups.com, mikioh.mikioh@gmail.com), Please take another look.
13 years ago (2013年01月08日 15:59:05 UTC) #6
Sign in to reply to this message.
rsc
Let's reject [] anywhere other than in the [host]:port form.
13 years ago (2013年01月09日 19:19:12 UTC) #7
Let's reject [] anywhere other than in the [host]:port form.
Sign in to reply to this message.
knieriem
Hello dave@cheney.net, rsc@golang.org (cc: golang-dev@googlegroups.com, mikioh.mikioh@gmail.com), Please take another look.
13 years ago (2013年01月09日 22:38:18 UTC) #8
Sign in to reply to this message.
knieriem
On Wed, 9 Jan 2013 14:19:10 -0500 Russ Cox <rsc@golang.org> wrote: > Let's reject [] ...
13 years ago (2013年01月09日 22:40:15 UTC) #9
On Wed, 9 Jan 2013 14:19:10 -0500
Russ Cox <rsc@golang.org> wrote:
> Let's reject [] anywhere other than in the [host]:port form.
> 
I've adjusted the patch so that SplitHostPort works that way now.
The (updated) program showing the differences between go1.0.3
and the patched version can be found at:
	http://play.golang.org/p/eZ1H5z-F10
Sign in to reply to this message.
rsc
LGTM Perhaps mikio would like to look too.
12 years, 12 months ago (2013年01月18日 20:15:35 UTC) #10
LGTM
Perhaps mikio would like to look too.
Sign in to reply to this message.
mikio
LGTM leave for rsc
12 years, 12 months ago (2013年01月19日 00:33:58 UTC) #11
LGTM
leave for rsc
Sign in to reply to this message.
rsc
LGTM Hi Michael, It looks like you still need to complete a CLA as described ...
12 years, 11 months ago (2013年01月22日 22:03:40 UTC) #12
LGTM
Hi Michael,
It looks like you still need to complete a CLA as described at
http://golang.org/doc/contribute.html#copyright.
Thanks.
Russ
Sign in to reply to this message.
rsc
*** Submitted as https://code.google.com/p/go/source/detail?r=4b48471048eb *** net: SplitHostPort: adjust error message for missing port in IPv6 ...
12 years, 11 months ago (2013年01月30日 17:25:21 UTC) #13
*** Submitted as https://code.google.com/p/go/source/detail?r=4b48471048eb ***
net: SplitHostPort: adjust error message for missing port in IPv6 addresses
An hostport of "[::1]" now results in the same error message
"missing port in address" as the hostport value "127.0.0.1",
so SplitHostPort won't complain about "too many colons
in address" anymore for an IPv6 address missing a port.
Added tests checking the error values.
Fixes issue 4526.
R=dave, rsc, mikioh.mikioh
CC=golang-dev
https://codereview.appspot.com/7038045
Committer: Russ Cox <rsc@golang.org>
Sign in to reply to this message.
|
This is Rietveld f62528b

AltStyle によって変換されたページ (->オリジナル) /