Zensavona / domainatrex

:smiling_imp: A library for parsing TLDs from urls in Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Domainatrex.parse raises an unhandled exception when passed a TLD

axelson opened this issue · comments

Similar error to #3 I get the following error on "is.it":

iex(23)> Domainatrex.parse("is.it")
** (MatchError) no match of right hand side value: []
    (domainatrex) lib/domainatrex.ex:65: Domainatrex.format_response/2
    (domainatrex) lib/domainatrex.ex:45: Domainatrex.match/1

It appears that if you pass Domainatrex a TLD directly then you get that MatchError

The same for .ru domains:

iex(1)> Domainatrex.parse("test.ru")
** (MatchError) no match of right hand side value: []
    (domainatrex) lib/domainatrex.ex:65: Domainatrex.format_response/2
    (domainatrex) lib/domainatrex.ex:45: Domainatrex.match/1

@quolpr That is because test.ru is actually a TLD (Top Level Domain). If you pass a non-top-level .ru domain it works fine.

iex(1)> Domainatrex.parse("test.ru")
** (MatchError) no match of right hand side value: []
    (domainatrex) lib/domainatrex.ex:65: Domainatrex.format_response/2
    (domainatrex) lib/domainatrex.ex:45: Domainatrex.match/1
iex(1)> Domainatrex.parse("testa.ru")
{:ok, %{domain: "testa", subdomain: "", tld: "ru"}}

Also, FYI I've moved to using the public suffix library instead of Domainatrex, it's proven much more stable for me (although the use case is perhaps slightly different).