开发者

Why FILTER_VALIDATE_URL return FALSE for only this url?

开发者 https://www.devze.com 2022-12-26 05:32 出处:网络
i have the following code: $url = \"http://icons3.iconfinder.netdna-cdn.com/data/icons/pool/poolbird.png\";

i have the following code:

$url = "http://icons3.iconfinder.netdna-cdn.com/data/icons/pool/poolbird.png";

if (filter_var ($url, FILTER_VALIDATE_URL) === FALSE) {

    echo "Invalid Url";
    exit;

} else {

    echo "Works!";
}

This displays:

invalid url (FALSE)

for the above url, but not for other simpler urls. Is this a bug? you can even access the image.

And the most impo开发者_Go百科rtant is what's the solution for this?

Thanks


PHP < 5.2.13 contains a bug in FILTER_VALIDATE_URL that considers urls containing the '-' (http://bugs.php.net/51192). You either need to upgrade your copy of php or use a different filtering mechanism.


That code prints "Works!" for me. What version of PHP are you using? Can you post a link to a PHP page containing:

<?php phpinfo(); ?>

Also, see this question.


Running PHP 5.2.13, I get this response when trying to filter a valid URL:

php > var_dump(filter_var("http://www.asdf-asdf.com", FILTER_VALIDATE_URL));
bool(false)

This is clearly not what I woukd expect it to return. The domain is valid.

This has evidently been fixed now, and will be included in PHP 5.3.3 and 5.2.14, more info in this bugreport: http://bugs.php.net/bug.php?id=51192


The source archive from http://www.php.net/get/php-5.3.2.tar.bz2/from/a/mirror contains a strange version of ext/filter/logical_filter.c, a version I can't find in the cvs. This version performs an "extra" test on the host part of the url

e = url->host + strlen(url->host);
s = url->host;

while (s < e) {
  if (!isalnum((int)*(unsigned char *)s) && *s != '_' && *s != '.') {
    goto bad_url;
  }
  s++;
}

which doesn't allow a hyphen in the host name like in icons3.iconfinder.netdna-cdn.com
Very strange and very wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号