Browse Source

Don't add a '.' prefix on the record header on apex records

Ask Bjørn Hansen 11 years ago
parent
commit
a68f1617fa
2 changed files with 13 additions and 3 deletions
  1. 10 3
      zones.go
  2. 3 0
      zones_test.go

+ 10 - 3
zones.go

@@ -3,8 +3,6 @@ package main
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/abh/dns"
-	"github.com/abh/errorutil"
 	"io/ioutil"
 	"log"
 	"net"
@@ -15,6 +13,9 @@ import (
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/abh/dns"
+	"github.com/abh/errorutil"
 )
 
 // Zones maps domain names to zone data
@@ -300,7 +301,13 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {
 				h.Ttl = uint32(label.Ttl)
 				h.Class = dns.ClassINET
 				h.Rrtype = dnsType
-				h.Name = label.Label + "." + Zone.Origin + "."
+
+				switch len(label.Label) {
+				case 0:
+					h.Name = Zone.Origin + "."
+				default:
+					h.Name = label.Label + "." + Zone.Origin + "."
+				}
 
 				switch dnsType {
 				case dns.TypeA, dns.TypeAAAA:

+ 3 - 0
zones_test.go

@@ -62,6 +62,9 @@ func (s *ConfigSuite) TestReadConfigs(c *C) {
 		firstRR(dns.TypeMF).(*dns.MF).
 		Mf, Equals, "www")
 
+	// The header name should just have a dot-prefix
+	c.Check(tz.Labels[""].Records[dns.TypeNS][0].RR.(*dns.NS).Hdr.Name, Equals, "test.example.com.")
+
 }
 
 func (s *ConfigSuite) TestRemoveConfig(c *C) {