Subham has uploaded this change for review.
netip: fix error messages in ParsePrefix
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Also, fixed some formatting and consistency issues in documentation (e.g., s/zeros/zeroes).
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
---
M src/net/netip/inlining_test.go
M src/net/netip/netip.go
M src/net/netip/netip_test.go
3 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/src/net/netip/inlining_test.go b/src/net/netip/inlining_test.go
index 52991be..975af39 100644
--- a/src/net/netip/inlining_test.go
+++ b/src/net/netip/inlining_test.go
@@ -5,12 +5,13 @@
package netip
import (
- "internal/testenv"
"os/exec"
"regexp"
"runtime"
"strings"
"testing"
+
+ "internal/testenv"
)
func TestInlining(t *testing.T) {
diff --git a/src/net/netip/netip.go b/src/net/netip/netip.go
index eae9c29..3a57b60 100644
--- a/src/net/netip/netip.go
+++ b/src/net/netip/netip.go
@@ -91,7 +91,7 @@
// AddrFrom16 returns the IPv6 address given by the bytes in addr.
// An IPv4-mapped IPv6 address is left as an IPv6 address.
-// (Use Unmap to convert them if needed.)
+// (Use Addr.Unmap to convert them if needed.)
func AddrFrom16(addr [16]byte) Addr {
return Addr{
addr: uint128{
@@ -334,7 +334,7 @@
}
} else if ellipsis >= 0 {
// Ellipsis must represent at least one 0 group.
- return Addr{}, parseAddrError{in: in, msg: "the :: must expand to at least one field of zeros"}
+ return Addr{}, parseAddrError{in: in, msg: "the :: must expand to at least one field of zeroes"}
}
return AddrFrom16(ip).WithZone(zone), nil
}
@@ -722,7 +722,7 @@
ip.addr = ip.addr.addOne()
if ip.Is4() {
if uint32(ip.addr.lo) == 0 {
- // Overflowed.
+ // Overflowed
return Addr{}
}
} else {
@@ -862,7 +862,7 @@
// string6 formats ip in IPv6 textual representation. It follows the
// guidelines in section 4 of RFC 5952
// (https://tools.ietf.org/html/rfc5952#section-4): no unnecessary
-// zeros, use :: to elide the longest run of zeros, and don't use ::
+// zeroes, use :: to elide the longest run of zeroes, and don't use ::
// to compact a single zero field.
func (ip Addr) string6() string {
// Use a zone with a "plausibly long" name, so that most zone-ful
@@ -964,7 +964,6 @@
}
return ip.appendTo6(b), nil
}
-
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
@@ -1292,7 +1291,7 @@
// IPv6 zones are not permitted in prefixes, and an error will be returned if a
// zone is present.
//
-// Note that masked address bits are not zeroed. Use Masked for that.
+// Note that masked address bits are not zeroed. Use Prefix.Masked for that.
func ParsePrefix(s string) (Prefix, error) {
i := stringsLastIndexByte(s, '/')
if i < 0 {
@@ -1310,14 +1309,14 @@
bitsStr := s[i+1:]
bits, err := strconv.Atoi(bitsStr)
if err != nil {
- return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + ": bad bits after slash: " + strconv.Quote(bitsStr))
+ return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + "): bad bits after slash: " + strconv.Quote(bitsStr))
}
maxBits := 32
if ip.Is6() {
maxBits = 128
}
if bits < 0 || bits > maxBits {
- return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + ": prefix length out of range")
+ return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + "): prefix length out of range")
}
return PrefixFrom(ip, bits), nil
}
diff --git a/src/net/netip/netip_test.go b/src/net/netip/netip_test.go
index 74dcc97..0e73731e 100644
--- a/src/net/netip/netip_test.go
+++ b/src/net/netip/netip_test.go
@@ -9,14 +9,15 @@
"encoding/json"
"flag"
"fmt"
- "internal/intern"
- "internal/testenv"
"net"
. "net/netip"
"reflect"
"sort"
"strings"
"testing"
+
+ "internal/intern"
+ "internal/testenv"
)
var long = flag.Bool("long", false, "run long tests")
@@ -30,7 +31,7 @@
)
func TestParseAddr(t *testing.T) {
- var validIPs = []struct {
+ validIPs := []struct {
in string
ip Addr // output of ParseAddr()
str string // output of String(). If "", use in.
@@ -210,7 +211,7 @@
})
}
- var invalidIPs = []string{
+ invalidIPs := []string{
// Empty string
"",
// Garbage non-IP
@@ -828,7 +829,7 @@
values := []Addr{
mustIP("::1"),
mustIP("::2"),
- Addr{},
+ {},
mustIP("1.2.3.4"),
mustIP("8.8.8.8"),
mustIP("::1%foo"),
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Subham uploaded patch set #2 to this change.
net/netip: fix error messages in ParsePrefix
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Also, fixed some formatting and consistency issues in documentation (e.g., s/zeros/zeroes).
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
---
M src/net/netip/inlining_test.go
M src/net/netip/netip.go
M src/net/netip/netip_test.go
3 files changed, 43 insertions(+), 14 deletions(-)
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor.
Subham uploaded patch set #3 to this change.
net/netip: fix error messages in ParsePrefix
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
For the following snippet:
```
_, err := netip.ParsePrefix("::/130")
// print error
_, err = netip.ParsePrefix("::/five")
// print error
```
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Also, fixed some formatting and consistency issues in documentation (e.g., s/zeros/zeroes).
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
---
M src/net/netip/inlining_test.go
M src/net/netip/netip.go
M src/net/netip/netip_test.go
3 files changed, 52 insertions(+), 14 deletions(-)
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Subham.
3 comments:
Commit Message:
Patch Set #3, Line 7: net/netip: fix error messages in ParsePrefix
"fix" doesn't really say what changed. Better to write
net/netip: add missing ) in ParsePrefix errors
File src/net/netip/inlining_test.go:
This seems like an unrelated change. Please do not combine functional changes and cleanup changes in a single patch. Please send two separate patches. Thanks.
File src/net/netip/netip.go:
Patch Set #3, Line 337: return Addr{}, parseAddrError{in: in, msg: "the :: must expand to at least one field of zeroes"}
"zeros" is correct in American English, I don't see a reason to change anything here.
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Subham.
Subham uploaded patch set #4 to this change.
net/netip: add missing ) in ParsePrefix errors
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
For the following snippet:
```
_, err := netip.ParsePrefix("::/130")
// print error
_, err = netip.ParsePrefix("::/five")
// print error
```
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
---
M src/net/netip/inlining_test.go
M src/net/netip/netip.go
M src/net/netip/netip_test.go
3 files changed, 50 insertions(+), 14 deletions(-)
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Subham.
Subham uploaded patch set #5 to this change.
net/netip: fix error messages in ParsePrefix
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
For the following snippet:
```
_, err := netip.ParsePrefix("::/130")
// print error
_, err = netip.ParsePrefix("::/five")
// print error
```
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Also, fixed some formatting and consistency issues in documentation (e.g., s/zeros/zeroes).
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
---
M src/net/netip/inlining_test.go
M src/net/netip/netip.go
M src/net/netip/netip_test.go
3 files changed, 52 insertions(+), 14 deletions(-)
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Subham.
Subham uploaded patch set #6 to this change.
net/netip: add missing ) in ParsePrefix errors
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
For the following snippet:
```
_, err := netip.ParsePrefix("::/130")
// print error
_, err = netip.ParsePrefix("::/five")
// print error
```
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
---
M src/net/netip/netip.go
1 file changed, 37 insertions(+), 2 deletions(-)
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor.
4 comments:
Commit Message:
Patch Set #3, Line 7: net/netip: fix error messages in ParsePrefix
"fix" doesn't really say what changed. Better to write […]
Ya, right.
Looks good to me:
"""
net/netip: add missing ) in ParsePrefix errors
"""
Patchset:
@iant, I've addressed the review comments.
File src/net/netip/inlining_test.go:
This seems like an unrelated change. […]
Sure.
File src/net/netip/netip.go:
Patch Set #3, Line 337: return Addr{}, parseAddrError{in: in, msg: "the :: must expand to at least one field of zeroes"}
"zeros" is correct in American English, I don't see a reason to change anything here.
In the same file, you'd find both — "zeros" and "zeroes"; so chose the latter and replaced "zeros" with "zeroes".
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor.
1 comment:
Patchset:
Ian and Damien, please have a look? If merged, it can be included in the next Go 1.19 beta release.
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor, Subham.
1 comment:
Commit Message:
For the following snippet:
```
_, err := netip.ParsePrefix("::/130")
// print error
_, err = netip.ParsePrefix("::/five")
// print error
```
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Please don't use markdown in the commit message per https://go.dev/wiki/CommitMessage.
I think you can drop this part of the commit message entirely. The diff and first paragraph should be enough to understand the change.
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor, Subham.
Subham uploaded patch set #7 to this change.
net/netip: add missing ) in ParsePrefix errors
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
---
M src/net/netip/netip.go
1 file changed, 16 insertions(+), 2 deletions(-)
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor, Tobias Klauser.
1 comment:
Commit Message:
For the following snippet:
```
_, err := netip.ParsePrefix("::/130")
// print error
_, err = netip.ParsePrefix("::/five")
// print error
```
Older error messages:
"""
netip.ParsePrefix("::/130": prefix length out of range
netip.ParsePrefix("::/five": bad bits after slash: "five"
"""
Current error messages:
"""
netip.ParsePrefix("::/130"): prefix length out of range
netip.ParsePrefix("::/five"): bad bits after slash: "five"
"""
Please don't use markdown in the commit message per https://go.dev/wiki/CommitMessage. […]
Done
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil, Ian Lance Taylor, Subham.
Patch set 7:Run-TryBot +1Auto-Submit +1Code-Review +2
Attention is currently required from: Ian Lance Taylor, Subham.
Patch set 7:Code-Review +2
Attention is currently required from: Ian Lance Taylor, Subham.
Patch set 7:Run-TryBot +1Auto-Submit +1Code-Review +2
1 comment:
Patchset:
Thanks.
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Subham.
1 comment:
Patchset:
Ian and Damien, please have a look? If merged, it can be included in the next Go 1.19 beta release.
Ack
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.
Gopher Robot submitted this change.
net/netip: add missing ) in ParsePrefix errors
The existing error messages didn't add right parenthesis ')' properly
leading to improper formation of error messages.
Fixes #53283
Change-Id: Iadf9b8059403efa07e39716a81fab68cd10b7f87
Reviewed-on: https://go-review.googlesource.com/c/go/+/411015
Auto-Submit: Tobias Klauser <tobias....@gmail.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Reviewed-by: Ian Lance Taylor <ia...@google.com>
Auto-Submit: Ian Lance Taylor <ia...@google.com>
Run-TryBot: Tobias Klauser <tobias....@gmail.com>
Run-TryBot: Ian Lance Taylor <ia...@google.com>
Reviewed-by: Tobias Klauser <tobias....@gmail.com>
Reviewed-by: Damien Neil <dn...@google.com>
---
M src/net/netip/netip.go
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/net/netip/netip.go b/src/net/netip/netip.go
index eae9c29..bb83371 100644
--- a/src/net/netip/netip.go
+++ b/src/net/netip/netip.go
@@ -1310,14 +1310,14 @@
bitsStr := s[i+1:]
bits, err := strconv.Atoi(bitsStr)
if err != nil {
- return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + ": bad bits after slash: " + strconv.Quote(bitsStr))
+ return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + "): bad bits after slash: " + strconv.Quote(bitsStr))
}
maxBits := 32
if ip.Is6() {
maxBits = 128
}
if bits < 0 || bits > maxBits {
- return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + ": prefix length out of range")
+ return Prefix{}, errors.New("netip.ParsePrefix(" + strconv.Quote(s) + "): prefix length out of range")
}
return PrefixFrom(ip, bits), nil
}
To view, visit change 411015. To unsubscribe, or for help writing mail filters, visit settings.