isValidHostname throws exception on valid hostnames
chrisleavoy opened this issue · comments
https://github.com/amphp/dns/blame/master/lib/DefaultResolver.php#L87
2.0.0.127.b.barracudacentral.org is a prefectly valid hostname that doesn't match the regex.
Suggest instead:
$pattern = "/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$/i";
It appears the top answer on stackoverflow is wrong: http://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
Note that we have two functions, query() and resolve(). The latter one is explicitly for hostname/IP (as defined per RFC 1123 2.1) resolving (will check /etc/hosts too and recurses (CNAME) by default), the former for arbitrary name resolving.
Just use query() if you want to resolve that one.
I shall maybe change the error message to explicitly reference RFC 1123 2.1 and give a hint at the query() function though... (As I can imagine this to be a common mistake) (Doing this tomorrow).
@bwoebi: That one is a valid hostname. It's not a documentation issue, it's a RegEx issue.
Oh, you are right. Will fix that then.
@bwoebi You wanted to work on it, is that still the case?
Sorry for the delay… Forgotten about it and only rediscovered it today.