Skip to content

Commit

Permalink
fix: trim the response of url:URL before parsing it (#709)
Browse files Browse the repository at this point in the history
The idea was adapted from the following commit:
gizmo-ds@3a66d70

The original author is https://github.com/gizmo-ds
  • Loading branch information
favonia committed Mar 11, 2024
1 parent a4f1458 commit 48edb15
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/provider/protocol/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net/http"
"net/netip"
"strings"

"github.com/favonia/cloudflare-ddns/internal/ipnet"
"github.com/favonia/cloudflare-ddns/internal/pp"
Expand All @@ -16,7 +17,7 @@ func getIPFromHTTP(ctx context.Context, ppfmt pp.PP, url string) (netip.Addr, bo
additionalHeaders: nil,
requestBody: nil,
extract: func(_ pp.PP, body []byte) (netip.Addr, bool) {
ipString := string(body)
ipString := strings.TrimSpace(string(body))
ip, err := netip.ParseAddr(ipString)
if err != nil {
ppfmt.Errorf(pp.EmojiImpossible, `Failed to parse the IP address in the response of %q: %s`, url, ipString)
Expand Down

0 comments on commit 48edb15

Please sign in to comment.