[pve-devel] [PATCH v3 common] fix #2111: regex match for email addresses

Dominik Csapak d.csapak at proxmox.com
Thu Feb 28 13:59:47 CET 2019


On 2/28/19 1:40 PM, Oguz Bektas wrote:
> now allows:
> * addresses without tld (such as user at localhost per bug)
> * change the min char limit from 2 to 1 in the host part
> * allow more than 5 subdomains
> * allow addresses ending with +, -
> 
> also used the backslash escape character in the character sets, in
> hopes of improving readability.
> 
> Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> ---
>   src/PVE/JSONSchema.pm | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
> index 36fa994..1f93a6b 100644
> --- a/src/PVE/JSONSchema.pm
> +++ b/src/PVE/JSONSchema.pm
> @@ -356,8 +356,7 @@ register_format('email', \&pve_verify_email);
>   sub pve_verify_email {
>       my ($email, $noerr) = @_;
>   
> -    # we use same regex as in Utils.js
> -    if ($email !~ /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/) {
> +    if ($email !~ /^\w+([\+\-\.]\w*)*@([a-zA-Z0-9\-]+\.)*([a-zA-Z0-9\-]){1,63}$/) {

i would like to see underscore '_' and tilde '~' as well in the local part

also the \w* part should be \w+ ?
else we would accept non standard conform mail addresses like
foo. at bar.com
foo..bar at baz.com

dots are not allowed:
* at the beginning or end
* one after another

if the mail address is not quoted (which we do not support)

>   	   return undef if $noerr;
>   	   die "value does not look like a valid email address\n";
>       }
> 





More information about the pve-devel mailing list