Skip to content

Commit 34275a3

Browse files
committed
Handle empty string in stripUnderscore to avoid panic
...by using strings.TrimPrefix. This was identified by the Cursor AI tool. Signed-off-by: Tom Pantelis <[email protected]>
1 parent 9aec66f commit 34275a3

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

coredns/plugin/parse.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ limitations under the License.
1919
package lighthouse
2020

2121
import (
22+
"strings"
23+
2224
"github.com/coredns/coredns/plugin/pkg/dnsutil"
2325
"github.com/coredns/coredns/request"
2426
"github.com/miekg/dns"
@@ -151,9 +153,5 @@ func parseSegments(segs []string, count int, r *recordRequest, qType uint16) (*r
151153

152154
// stripUnderscore removes a prefixed underscore from s.
153155
func stripUnderscore(s string) string {
154-
if s[0] != '_' {
155-
return s
156-
}
157-
158-
return s[1:]
156+
return strings.TrimPrefix(s, "_")
159157
}

0 commit comments

Comments
 (0)