Improve sanitizing functions for mail and url

This commit is contained in:
Joshua Ramon Enslin 2020-09-04 01:19:00 +02:00 committed by Stefan Rohde-Enslin
parent 55db406401
commit f478728ab9

View File

@ -145,10 +145,10 @@ final class MD_STD_IN {
*/
final public static function sanitize_url($input):string {
if ($input === "") return $input;
if ($input === "") return "";
$output = \filter_var($input, FILTER_SANITIZE_URL);
if (\filter_var($input, FILTER_VALIDATE_URL) === false) {
if (\filter_var($output, FILTER_VALIDATE_URL) === false) {
throw new MDInvalidUrl("Invalid input URL");
}
@ -165,10 +165,10 @@ final class MD_STD_IN {
*/
final public static function sanitize_email($input):string {
if ($input === "") return $input;
if ($input === "") return "";
$output = \filter_var($input, FILTER_SANITIZE_EMAIL);
if (\filter_var($input, FILTER_VALIDATE_EMAIL) === false) {
if (\filter_var($output, FILTER_VALIDATE_EMAIL) === false) {
throw new MDInvalidEmail("Invalid input email address");
}