|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-05-31 09:26 UTC] ian+php at ians-net dot co dot uk
Description: ------------ RFC3986 allows scheme relative URLs, also termed network-path references. These are commonly used to ensure the appropriate protocol is used to fetch the resource regardless of whether the resource is embedded in a http or https page. filter_var($url, FILTER_VALIDATE_URL) does not correctly validate these URLs See also https://tools.ietf.org/html/rfc3986#section-4.2 https://url.spec.whatwg.org/#syntax-url-scheme-relative Test script: --------------- var_dump(filter_var("//google.com/", FILTER_VALIDATE_URL)); Expected result: ---------------- bool(true) Actual result: -------------- bool(false) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 20:00:02 2025 UTC |
The problem is that FILTER_VALIDATE_URL uses RFC 2396 which is older than RFC 3986. This would have been OK if the language was consistent in the URL RFC it was using, however parse_url seems to be using RFC3986, making the following code to behave unexpectedly. if (filter_var($url,FILTER_VALIDATE_URL)) { $parts = parse_url($url); } Note: I am only assuming that parse_url uses RFC 3986 because there's a link to it in the "see also" links of http://php.net/manual/en/function.parse-url.php