Closed
Description
Description
Hello,
The following code:
<?php
$domains = [
'a-.bc.com',
'a.bc-.com',
'a.bc.com-',
];
foreach ($domains as $domain) {
echo $domain . PHP_EOL;
var_dump(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
echo PHP_EOL;
}
Resulted in this output:
a-.bc.com
bool(false)
a.bc-.com
bool(false)
a.bc.com-
string(9) "a.bc.com-" // <------------ here is the bug
I expected this output instead: a.bc.com-
test should return false.
I thought that the ending hyphen is not permitted on domain name (https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.1).
This code is tested here : https://3v4l.org/XbMCV
This bug happens in PHP 8.1.30, PHP 8.2.24 and PHP 8.3.12
PHP Version
PHP 8.3.12