Trim trailing dots from DNS names
This commit is contained in:
parent
3c220e56f6
commit
ca8f60740a
|
@ -22,6 +22,14 @@ func DefaultStateDir () string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func trimTrailingDots (value string) string {
|
||||||
|
length := len(value)
|
||||||
|
for length > 0 && value[length - 1] == '.' {
|
||||||
|
length--
|
||||||
|
}
|
||||||
|
return value[0:length]
|
||||||
|
}
|
||||||
|
|
||||||
var stateDir = flag.String("state_dir", DefaultStateDir(), "Directory for storing state")
|
var stateDir = flag.String("state_dir", DefaultStateDir(), "Directory for storing state")
|
||||||
var watchDomains []string
|
var watchDomains []string
|
||||||
var watchDomainSuffixes []string
|
var watchDomainSuffixes []string
|
||||||
|
@ -38,7 +46,7 @@ func setWatchDomains (domains []string) error {
|
||||||
watchDomainSuffixes = []string{""}
|
watchDomainSuffixes = []string{""}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
asciiDomain, err := idna.ToASCII(strings.ToLower(domain))
|
asciiDomain, err := idna.ToASCII(strings.ToLower(trimTrailingDots(domain)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Invalid domain `%s': %s", domain, err)
|
return fmt.Errorf("Invalid domain `%s': %s", domain, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,9 +87,17 @@ func isValidDNSLabel (label string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func trimTrailingDots (value string) string {
|
||||||
|
length := len(value)
|
||||||
|
for length > 0 && value[length - 1] == '.' {
|
||||||
|
length--
|
||||||
|
}
|
||||||
|
return value[0:length]
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the DNS name to lower case and replace invalid labels with a placeholder
|
// Convert the DNS name to lower case and replace invalid labels with a placeholder
|
||||||
func sanitizeDNSName (value string) string {
|
func sanitizeDNSName (value string) string {
|
||||||
value = strings.ToLower(value)
|
value = strings.ToLower(trimTrailingDots(value))
|
||||||
labels := strings.Split(value, ".")
|
labels := strings.Split(value, ".")
|
||||||
for i, label := range labels {
|
for i, label := range labels {
|
||||||
if !isValidDNSLabel(label) {
|
if !isValidDNSLabel(label) {
|
||||||
|
@ -101,7 +109,7 @@ func sanitizeDNSName (value string) string {
|
||||||
|
|
||||||
// Like sanitizeDNSName, but labels that are Unicode are converted to Punycode.
|
// Like sanitizeDNSName, but labels that are Unicode are converted to Punycode.
|
||||||
func sanitizeUnicodeDNSName (value string) string {
|
func sanitizeUnicodeDNSName (value string) string {
|
||||||
value = strings.ToLower(value)
|
value = strings.ToLower(trimTrailingDots(value))
|
||||||
labels := strings.Split(value, ".")
|
labels := strings.Split(value, ".")
|
||||||
for i, label := range labels {
|
for i, label := range labels {
|
||||||
if asciiLabel, err := idna.ToASCII(label); err == nil && isValidDNSLabel(asciiLabel) {
|
if asciiLabel, err := idna.ToASCII(label); err == nil && isValidDNSLabel(asciiLabel) {
|
||||||
|
|
Loading…
Reference in New Issue