From c7cfc6b170c6e23780ba2a3134cbcb84ad02525c Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Thu, 14 Mar 2013 13:58:01 +0800 Subject: [PATCH] Use filter_var instead of parse_url to validate URLs, since the latter returns true even for invalid URLs, in particular the empty string --- include/network.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/network.php b/include/network.php index 941ef5e1b9..dce092eb95 100644 --- a/include/network.php +++ b/include/network.php @@ -93,8 +93,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ //$newurl = trim(array_pop($matches)); if(strpos($newurl,'/') === 0) $newurl = $url . $newurl; - $url_parsed = @parse_url($newurl); - if (isset($url_parsed)) { + if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; return fetch_url($newurl,$binary,$redirects,$timeout); } @@ -188,8 +187,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) $newurl = trim(array_pop($matches)); if(strpos($newurl,'/') === 0) $newurl = $url . $newurl; - $url_parsed = @parse_url($newurl); - if (isset($url_parsed)) { + if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; return fetch_url($newurl,false,$redirects,$timeout); }