egulias/EmailValidator

Index on $hostParts array looks wrong to me

Closed this issue · 1 comments

$isReservedTopLevel = in_array($hostParts[(count($hostParts) - 1)], self::RESERVED_DNS_TOP_LEVEL_NAMES, true);

Shouldn't it be $hostParts[(count($hostParts) - 2)] ?

Using count($hostParts) - 1 correctly identifies the top-level domain (TLD) because it retrieves the last element of the hostParts array, which is split by dots. For example, in example.com, hostParts is ['example', 'com'], and com is the TLD. Using count($hostParts) - 2 would incorrectly access the second-level domain, example, not the TLD.