Add wrappers for sanitizing URLs and mail addresses
This commit is contained in:
parent
6fe367ead7
commit
55db406401
@ -136,4 +136,44 @@ final class MD_STD_IN {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes and validates a URL. An empty string passes.
|
||||
*
|
||||
* @param mixed $input Input string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public static function sanitize_url($input):string {
|
||||
|
||||
if ($input === "") return $input;
|
||||
|
||||
$output = \filter_var($input, FILTER_SANITIZE_URL);
|
||||
if (\filter_var($input, FILTER_VALIDATE_URL) === false) {
|
||||
throw new MDInvalidUrl("Invalid input URL");
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes and validates an e-mail address. An empty string passes.
|
||||
*
|
||||
* @param mixed $input Input string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public static function sanitize_email($input):string {
|
||||
|
||||
if ($input === "") return $input;
|
||||
|
||||
$output = \filter_var($input, FILTER_SANITIZE_EMAIL);
|
||||
if (\filter_var($input, FILTER_VALIDATE_EMAIL) === false) {
|
||||
throw new MDInvalidEmail("Invalid input email address");
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user