mirror of
https://github.com/coredns/coredns.git
synced 2026-10-09 03:55:21 -04:00
plugin/etcd: Stop target stripping at the end of a name (#8584)
Stops stripping when the next-label operation reaches the end sentinel in DNS Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -165,6 +165,9 @@ func targetStrip(name string, targetStrip int) string {
|
||||
offset, end := 0, false
|
||||
for range targetStrip {
|
||||
offset, end = dns.NextLabel(name, offset)
|
||||
if end {
|
||||
break
|
||||
}
|
||||
}
|
||||
if end {
|
||||
// We overshot the name, use the original one.
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package msg
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSplit255(t *testing.T) {
|
||||
xs := split255("abc")
|
||||
@@ -29,6 +32,23 @@ func TestSplit255(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetStripLargeValueReturns(t *testing.T) {
|
||||
const name = "b.z1.test."
|
||||
done := make(chan string, 1)
|
||||
go func() {
|
||||
done <- targetStrip(name, int(^uint(0)>>1))
|
||||
}()
|
||||
|
||||
select {
|
||||
case got := <-done:
|
||||
if got != name {
|
||||
t.Fatalf("targetStrip returned %q, want %q", got, name)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("targetStrip did not return after reaching the end of the name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroup(t *testing.T) {
|
||||
// Key are in the wrong order, but for this test it does not matter.
|
||||
sx := Group(
|
||||
|
||||
Reference in New Issue
Block a user