Skip to content

Commit

Permalink
Reject number only entities, as they are ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Dec 18, 2023
1 parent d6e4c96 commit b76a860
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions profile/endpoints/endpoint-domain.go
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions profile/endpoints/endpoint_test.go
Expand Up @@ -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) {
Expand All @@ -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())
}
Expand Down

0 comments on commit b76a860

Please sign in to comment.