Skip to content

Commit

Permalink
fix url validate
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed May 15, 2023
1 parent 7a41f0d commit 98e4c1d
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions var/Typecho/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function maxLength(string $str, int $length): bool
public static function email(string $str): bool
{
$email = filter_var($str, FILTER_SANITIZE_EMAIL);
return filter_var($str, FILTER_VALIDATE_EMAIL) && ($email === $str);
return !!filter_var($str, FILTER_VALIDATE_EMAIL) && ($email === $str);
}

/**
Expand All @@ -111,14 +111,8 @@ public static function email(string $str): bool
*/
public static function url(string $str): bool
{
$parts = parse_url($str);
if (!$parts) {
return false;
}

return isset($parts['scheme']) &&
in_array($parts['scheme'], ['http', 'https']) &&
!preg_match('/(\(|\)|\\\|"|<|>|[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19])/', $str);
$url = Common::safeUrl($str);
return !!filter_var($str, FILTER_VALIDATE_URL) && ($url === $str);
}

/**
Expand Down

0 comments on commit 98e4c1d

Please sign in to comment.