From 27f26ed3d1ac00dbfef99c85b955ec2caaec74bc Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Thu, 24 Jan 2019 21:40:44 +0100 Subject: [PATCH] namecheap: fix panic. (#764) --- providers/dns/namecheap/namecheap.go | 8 +++++--- providers/dns/namecheap/namecheap_test.go | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/providers/dns/namecheap/namecheap.go b/providers/dns/namecheap/namecheap.go index 2bcf9198..e4749ab6 100644 --- a/providers/dns/namecheap/namecheap.go +++ b/providers/dns/namecheap/namecheap.go @@ -180,10 +180,12 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { // Find the challenge TXT record and remove it if found. var found bool - for i, h := range records { + var newRecords []Record + for _, h := range records { if h.Name == ch.key && h.Type == "TXT" { - records = append(records[:i], records[i+1:]...) found = true + } else { + newRecords = append(newRecords, h) } } @@ -191,7 +193,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } - err = d.setHosts(ch.sld, ch.tld, records) + err = d.setHosts(ch.sld, ch.tld, newRecords) if err != nil { return fmt.Errorf("namecheap: %v", err) } diff --git a/providers/dns/namecheap/namecheap_test.go b/providers/dns/namecheap/namecheap_test.go index ec084831..67a49d89 100644 --- a/providers/dns/namecheap/namecheap_test.go +++ b/providers/dns/namecheap/namecheap_test.go @@ -208,10 +208,10 @@ func mockServer(tc *testCase, t *testing.T) http.Handler { case "namecheap.domains.dns.getHosts": assertHdr(tc, t, &values) w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, tc.getHostsResponse) + fmt.Fprint(w, tc.getHostsResponse) case "namecheap.domains.getTldList": w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, responseGetTlds) + fmt.Fprint(w, responseGetTlds) default: t.Errorf("Unexpected GET command: %s", cmd) }