Skip to content

Commit

Permalink
fix: Support for .mx ccTLD (#20)
Browse files Browse the repository at this point in the history
Fix support for .mx ccTLD

Co-authored-by: TwiN <[email protected]>
  • Loading branch information
AlfredoRamos and TwiN authored Apr 27, 2024
1 parent 8df15f1 commit b59cc07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
ianaWHOISServerAddress = "whois.iana.org:43"
)

var tldWithoutExpirationDate = []string{"at", "be", "ch", "co.at", "com.br", "or.at", "de", "fr", "me", "mx", "nl"}
var tldWithoutExpirationDate = []string{"at", "be", "ch", "co.at", "com.br", "or.at", "de", "fr", "me", "nl"}

type Client struct {
whoisServerAddress string
Expand Down Expand Up @@ -75,12 +75,13 @@ func (c *Client) Query(domain string) (string, error) {
}
var output string
var err error
if domainExtension == "ua" {
switch domainExtension {
case "ua", "mx":
if len(parts) > 2 && len(parts[len(parts)-2]) < 4 {
domainExtension = parts[len(parts)-2] + "." + domainExtension
}
output, err = c.query("whois."+domainExtension+":43", domain)
} else {
default:
output, err = c.query(c.whoisServerAddress, domainExtension)
}
if err != nil {
Expand Down Expand Up @@ -162,6 +163,8 @@ func (c *Client) QueryAndParse(domain string) (*Response, error) {
response.ExpirationDate, _ = time.Parse("20060102", strings.ToUpper(value))
case strings.HasSuffix(domain, ".cn"):
response.ExpirationDate, _ = time.Parse("2006-01-02 15:04:05", strings.ToUpper(value))
case strings.HasSuffix(domain, ".mx"):
response.ExpirationDate, _ = time.Parse(time.DateOnly, strings.ToUpper(value))
default:
response.ExpirationDate, _ = time.Parse(time.RFC3339, strings.ToUpper(value))
}
Expand Down
6 changes: 5 additions & 1 deletion whois_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func TestClient(t *testing.T) {
domain: "register.su", // expiration date in `paid-till` field
wantErr: false,
},
{
domain: "nic.mx",
wantErr: false,
},
}
client := NewClient().WithReferralCache(true)
for _, scenario := range scenarios {
Expand Down Expand Up @@ -126,7 +130,7 @@ func TestClient(t *testing.T) {
if len(response.NameServers) == 0 {
t.Errorf("expected to have at least one name server for domain %s", scenario.domain)
}
if len(response.DomainStatuses) == 0 && !strings.HasSuffix(scenario.domain, ".im") {
if len(response.DomainStatuses) == 0 && !strings.HasSuffix(scenario.domain, ".im") && !strings.HasSuffix(scenario.domain, ".mx") {
t.Errorf("expected to have at least one domain status for domain %s", scenario.domain)
}
}
Expand Down

0 comments on commit b59cc07

Please sign in to comment.