Make toRadixName much faster
fix bug when a escape is escaped: \\. This last dot is now a real domain label seperator dot.
This commit is contained in:
parent
36af583ccf
commit
82cfe822ff
17
zone.go
17
zone.go
|
@ -109,17 +109,28 @@ func NewZoneData(s string) *ZoneData {
|
|||
// we preserve the nsec ordering of the zone (this idea was stolen from NSD).
|
||||
// Each label is also lowercased. The name given must be fully qualified.
|
||||
func toRadixName(d string) string {
|
||||
if d == "." {
|
||||
if d == "" || d == "." {
|
||||
return "."
|
||||
}
|
||||
s := ""
|
||||
ld := len(d)
|
||||
if d[ld-1] != '.' {
|
||||
d = d + "."
|
||||
ld++
|
||||
}
|
||||
var lastdot int
|
||||
var lastbyte byte
|
||||
var lastlastbyte byte
|
||||
for i := 0; i < len(d); i++ {
|
||||
if d[i] == '.' && lastbyte != '\\' && lastlastbyte != '\\' {
|
||||
if d[i] == '.' {
|
||||
switch {
|
||||
case lastbyte != '\\':
|
||||
fallthrough
|
||||
case lastbyte == '\\' && lastlastbyte == '\\':
|
||||
s = d[lastdot:i] + "." + s
|
||||
lastdot = i+1
|
||||
lastdot = i + 1
|
||||
continue
|
||||
}
|
||||
}
|
||||
lastlastbyte = lastbyte
|
||||
lastbyte = d[i]
|
||||
|
|
|
@ -8,8 +8,11 @@ func TestRadixName(t *testing.T) {
|
|||
tests := map[string]string{".": ".",
|
||||
"www.miek.nl.": ".nl.miek.www",
|
||||
"miek.nl.": ".nl.miek",
|
||||
"mi\\.ek.nl.": ".nl.mi\\.ek",}
|
||||
"mi\\.ek.nl.": ".nl.mi\\.ek",
|
||||
`mi\\.ek.nl.`: `.nl.ek.mi\\`,
|
||||
"": "."}
|
||||
for i, o := range tests {
|
||||
t.Logf("%s %v\n", i, SplitLabels(i))
|
||||
if x := toRadixName(i); x != o {
|
||||
t.Logf("%s should convert to %s, not %s\n", i, o, x)
|
||||
t.Fail()
|
||||
|
|
Loading…
Reference in New Issue