php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80855 FILTER_VALIDATE_DOMAIN does not recognize emoji TLDs with FILTER_FLAG_HOSTNAME
Submitted: 2021-03-11 19:54 UTC Modified: 2021-03-11 20:32 UTC
From: vijaycs85 at gmail dot com Assigned:
Status: Not a bug Package: Filter related
PHP Version: 7.4.16 OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 31 = ?
Subscribe to this entry?

 
 [2021-03-11 19:54 UTC] vijaycs85 at gmail dot com
Description:
------------
There are some countries that allow Top Level Domains(TLDs) with emoji and the filter_var does not recognize them.

Reference:
https://tinyprojects.dev/projects/mailoji

Test script:
---------------
$domain_name = '⚡.kz';
$is_valid = filter_var($domain_name, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
var_dump($is_valid);

Expected result:
----------------
string(4) "⚡.kz"

Actual result:
--------------
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-11 20:10 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-03-11 20:10 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

https://www.php.net/manual/en/filter.filters.validate.php
> Optional flag FILTER_FLAG_HOSTNAME adds ability to specifically validate
> hostnames (they must start with an alphanumeric character and contain only
> alphanumerics or hyphens).

Note that ⚡.kz must be converted to punycode, ie. xn--57h.kz. That would be considered valid with the HOSTNAME flag.
 [2021-03-11 20:22 UTC] vijaycs85 at gmail dot com
>Note that ⚡.kz must be converted to punycode, ie. xn--57h.kz. That would be considered valid with the HOSTNAME flag.

Thanks for your quick reply and clarification.
 [2021-03-11 20:29 UTC] vijaycs85 at gmail dot com
Just for future reference, the below code provides the expected result.

$domain_name = '⚡.kz';
$is_valid = filter_var(idn_to_ascii($domain_name), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
var_dump($is_valid);

Output

string(10) "xn--57h.kz"
 [2021-03-11 20:32 UTC] requinix@php.net
Or don't use the HOSTNAME flag.

$domain_name = '⚡.kz';
$is_valid = filter_var($domain_name, FILTER_VALIDATE_DOMAIN);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC