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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vijaycs85 at gmail dot com
New email:
PHP Version: OS:

 

 [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-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 23:05:54 2022 UTC