|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-12-20 22:22 UTC] divinity76 at gmail dot com
Description:
------------
FILTER_VALIDATE_DOMAIN fail to realize that "example.org/wat" is not a domain (URL? guess you can say that. domain? don't think so.) - interestingly, FILTER_VALIDATE_DOMAIN works fine if FILTER_FLAG_HOSTNAME is provided, the bug is only present when FILTER_FLAG_HOSTNAME is not provided.
Test script:
---------------
<?php
var_dump(
filter_var('example.org/wat',FILTER_VALIDATE_DOMAIN),
filter_var('example.org/wat',FILTER_VALIDATE_DOMAIN,FILTER_FLAG_HOSTNAME)
);
Expected result:
----------------
bool(false)
bool(false)
Actual result:
--------------
string(15) "example.org/wat"
bool(false)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 10:00:01 2025 UTC |
FILTER_VALIDATE_DOMAIN is only looking at the lengths of the domain string and those of the bits between '.' characters (this is documented but doesn't seem hugely useful). var_dump( filter_var('***.****',FILTER_VALIDATE_DOMAIN), filter_var('!',FILTER_VALIDATE_DOMAIN), filter_var('*******',FILTER_VALIDATE_DOMAIN), filter_var(str_repeat('*', 63),FILTER_VALIDATE_DOMAIN), filter_var(str_repeat('*', 64),FILTER_VALIDATE_DOMAIN) // Too long ); Meanwhile, FILTER_FLAG_HOSTNAME rejects domains with legal hyphens: var_dump( // A hyphen with a well-known story behind it filter_var('experts-exchange.com', FILTER_VALIDATE_DOMAIN | FILTER_FLAG_HOSTNAME), // Punycode (Greek test TLD) filter_var('xn--jxalpdlp', FILTER_VALIDATE_DOMAIN | FILTER_FLAG_HOSTNAME) );@ a at b dot c dot de quote > Meanwhile, FILTER_FLAG_HOSTNAME rejects domains with legal hyphens: - actually, when filter_var is user properly, it allows those domains (FILTER_FLAG_HOSTNAME goes as the third argument, don't xor it into the 2nd argument) var_dump( // A hyphen with a well-known story behind it filter_var('experts-exchange.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME), // Punycode (Greek test TLD) filter_var('xn--jxalpdlp', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) ); returns bool(true) bool(true)