From b76a86071808af0c79b2086658832b3272d7b329 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 18 Dec 2023 17:08:29 +0100 Subject: [PATCH] Reject number only entities, as they are ambiguous --- profile/endpoints/endpoint-domain.go | 6 ++++++ profile/endpoints/endpoint_test.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/profile/endpoints/endpoint-domain.go b/profile/endpoints/endpoint-domain.go index d23a02e66..d82ccb5bf 100644 --- a/profile/endpoints/endpoint-domain.go +++ b/profile/endpoints/endpoint-domain.go @@ -107,6 +107,12 @@ func parseTypeDomain(fields []string) (Endpoint, error) { domain += "." } + // Check if this looks like an IP address. + // At least the TLDs has characters. + if looksLikeAnIP.MatchString(domain) { + return nil, nil + } + // Fix domain case. domain = strings.ToLower(domain) needValidFQDN := true diff --git a/profile/endpoints/endpoint_test.go b/profile/endpoints/endpoint_test.go index e4dbe4ff4..1af937e0d 100644 --- a/profile/endpoints/endpoint_test.go +++ b/profile/endpoints/endpoint_test.go @@ -59,6 +59,9 @@ func TestEndpointParsing(t *testing.T) { testParsing(t, "+ * UDP/1234") testParsing(t, "+ * TCP/HTTP") testParsing(t, "+ * TCP/80-443") + + // TODO: Test fails: + // testParsing(t, "+ 1234") } func testParsing(t *testing.T, value string) { @@ -69,6 +72,7 @@ func testParsing(t *testing.T, value string) { t.Error(err) return } + // t.Logf("%T: %+v", ep, ep) if value != ep.String() { t.Errorf(`stringified endpoint mismatch: original was "%s", parsed is "%s"`, value, ep.String()) }