mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
util/dnsname: normalize leading dots in ToFQDN.
Fixes #1888. Signed-off-by: David Anderson <dave@natulte.net>
This commit is contained in:
parent
c0a70f3a06
commit
dc32b4695c
@ -24,13 +24,16 @@ func ToFQDN(s string) (FQDN, error) {
|
|||||||
if isValidFQDN(s) {
|
if isValidFQDN(s) {
|
||||||
return FQDN(s), nil
|
return FQDN(s), nil
|
||||||
}
|
}
|
||||||
if len(s) == 0 {
|
if len(s) == 0 || s == "." {
|
||||||
return FQDN("."), nil
|
return FQDN("."), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if s[len(s)-1] == '.' {
|
if s[len(s)-1] == '.' {
|
||||||
s = s[:len(s)-1]
|
s = s[:len(s)-1]
|
||||||
}
|
}
|
||||||
|
if s[0] == '.' {
|
||||||
|
s = s[1:]
|
||||||
|
}
|
||||||
if len(s) > maxNameLength {
|
if len(s) > maxNameLength {
|
||||||
return "", fmt.Errorf("%q is too long to be a DNS name", s)
|
return "", fmt.Errorf("%q is too long to be a DNS name", s)
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,12 @@ func TestFQDN(t *testing.T) {
|
|||||||
{".", ".", false, 0},
|
{".", ".", false, 0},
|
||||||
{"foo.com", "foo.com.", false, 2},
|
{"foo.com", "foo.com.", false, 2},
|
||||||
{"foo.com.", "foo.com.", false, 2},
|
{"foo.com.", "foo.com.", false, 2},
|
||||||
|
{".foo.com.", "foo.com.", false, 2},
|
||||||
|
{".foo.com", "foo.com.", false, 2},
|
||||||
{"com", "com.", false, 1},
|
{"com", "com.", false, 1},
|
||||||
{"www.tailscale.com", "www.tailscale.com.", false, 3},
|
{"www.tailscale.com", "www.tailscale.com.", false, 3},
|
||||||
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com", "", true, 0},
|
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com", "", true, 0},
|
||||||
{strings.Repeat("aaaaa.", 60) + "com", "", true, 0},
|
{strings.Repeat("aaaaa.", 60) + "com", "", true, 0},
|
||||||
{".com", "", true, 0},
|
|
||||||
{"foo..com", "", true, 0},
|
{"foo..com", "", true, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user