From fe9ba42590199b5d46e6acda2584195338f5497d Mon Sep 17 00:00:00 2001 From: Chris O'Haver Date: Thu, 10 Feb 2022 09:00:27 -0500 Subject: [PATCH] plugin/autopath: Don't panic on empty token (#5169) * dont panic on empty token Signed-off-by: Chris O'Haver --- plugin/autopath/setup.go | 3 ++- plugin/autopath/setup_test.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/autopath/setup.go b/plugin/autopath/setup.go index ed536933a..a041e364c 100644 --- a/plugin/autopath/setup.go +++ b/plugin/autopath/setup.go @@ -2,6 +2,7 @@ package autopath import ( "fmt" + "strings" "github.com/coredns/caddy" "github.com/coredns/coredns/core/dnsserver" @@ -50,7 +51,7 @@ func autoPathParse(c *caddy.Controller) (*AutoPath, string, error) { return ap, "", fmt.Errorf("no resolv-conf specified") } resolv := zoneAndresolv[len(zoneAndresolv)-1] - if resolv[0] == '@' { + if strings.HasPrefix(resolv, "@") { mw = resolv[1:] } else { // assume file on disk diff --git a/plugin/autopath/setup_test.go b/plugin/autopath/setup_test.go index 5847e0de5..4644c7d59 100644 --- a/plugin/autopath/setup_test.go +++ b/plugin/autopath/setup_test.go @@ -33,6 +33,7 @@ func TestSetupAutoPath(t *testing.T) { // negative {`autopath kubernetes`, true, "", "", nil, "open kubernetes: no such file or directory"}, {`autopath`, true, "", "", nil, "no resolv-conf"}, + {`autopath ""`, true, "", "", nil, "no such file"}, } for i, test := range tests {