From 8586d713eff88daa56fa19383d4f1cfed66ae0a6 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 16 Sep 2023 01:51:04 +0300 Subject: [PATCH] fix url/host validation, remove lib dependencies --- src/library/valid.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/library/valid.php b/src/library/valid.php index 417083b..5f3bb48 100644 --- a/src/library/valid.php +++ b/src/library/valid.php @@ -15,6 +15,19 @@ class Valid return false; } + if (!filter_var(str_replace(['[',']'], false, $value), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) + { + array_push( + $error, + sprintf( + _('Host of "%s" not supported'), + $value + ) + ); + + return false; + } + if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $value))) { array_push( @@ -44,7 +57,7 @@ class Valid return false; } - if (!$url = Yggverse\Parser\Url::parse($value)) + if (!filter_var($value, FILTER_VALIDATE_URL)) { array_push( $error, @@ -57,12 +70,12 @@ class Valid return false; } - if (empty($url->host->name)) + if (!$host = parse_url($value, PHP_URL_HOST)) { array_push( $error, sprintf( - _('Could not init host name for URL "%s"'), + _('Could not init host for URL "%s"'), $value ) ); @@ -70,14 +83,14 @@ class Valid return false; } - if (!self::host($url->host->name, $error)) + if (!self::host($host, $error)) { array_push( $error, sprintf( - _('URL host "%s" not supported'), + _('URL "%s" has not supported host "%s"'), $value, - $url->host->name + $host, ) );