Skip to content

Commit

Permalink
Add gentler public suffix error. Closes #83.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Sep 27, 2017
1 parent 6df04fb commit a8c7e9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 11 additions & 5 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,18 @@ func checkDomainFormat(domain string) Issues {
"Invalid domain name",
"Please provide a domain that does not contain `..`")
}
if strings.Count(domain, ".") < 1 {

ps, _ := publicsuffix.PublicSuffix(domain)
if ps == domain {
return issues.addErrorf(
IssueCode("domain.format.only_one_label"),
"Invalid domain name",
"Please provide a domain with least two labels "+
"(e.g. `example.com` rather than `example` or `com`).")
IssueCode("domain.format.public_suffix"),
"Domain is a TLD or public suffix",
"You have entered a public suffix (ccTLD, gTLD, or other domain listed at "+
"https://publicsuffix.org/), which cannot be submitted through this website. "+
"If you intended to query for a normal website, make sure to enter all of its labels "+
"(e.g. `example.com` rather than `example` or `com`). If you operate a TLD "+
"or public suffix and are interested in preloading HSTS for it, "+
"please see https://hstspreload.org/#tld")
}

domain = strings.ToLower(domain)
Expand Down
5 changes: 4 additions & 1 deletion domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ var testCheckDomainFormatTests = []struct {
Issues{Errors: []Issue{{Code: "domain.format.contains_double_dot"}}},
},
{"example",
Issues{Errors: []Issue{{Code: "domain.format.only_one_label"}}},
Issues{Errors: []Issue{{Code: "domain.format.public_suffix"}}},
},
{"co.uk",
Issues{Errors: []Issue{{Code: "domain.format.public_suffix"}}},
},
{"example&co.com",
Issues{Errors: []Issue{{Code: "domain.format.invalid_characters"}}},
Expand Down

0 comments on commit a8c7e9c

Please sign in to comment.