简体   繁体   English

filter_var()接受无效的URL

[英]filter_var() accepts invalid URL

Why does filter_var() accepts and validate this URL http://http://www.google.com ? 为什么filter_var()接受并验证此URL http://http://www.google.com

$website = "http://http://www.google.com";

echo filter_var($website, FILTER_VALIDATE_URL); // This outputs the value of $website

I think this is wrong. 我认为这是错误的。 Any solution or fixed for this? 有解决方案或解决方案吗?

phpinfo()

在此处输入图片说明

Seems like you've found a bug in PHP. 似乎您已经发现PHP中的错误。 The PHP manual states that FILTER_VALIDATE_URL validates uris according to http://www.faqs.org/rfcs/rfc2396.html PHP手册指出FILTER_VALIDATE_URL根据http://www.faqs.org/rfcs/rfc2396.html验证了uris

If you read the spec, PHP obviously fails to properly validate per the guidelines. 如果您阅读该规范,PHP显然无法按照指南进行正确验证。 Specifically, in section 3 (URI Syntactic Components), it's defined that the scheme (http in your case) may only exist once, and precedes the only colon in the uri. 具体来说,在第3节(URI语法组件)中,定义了方案(在您的情况下为http)只能存在一次,并且位于uri中唯一的冒号之前。

You should report this bug at https://bugs.php.net/ 您应该在https://bugs.php.net/报告此错误。

Good work finding it! 好工作找到它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM