[pve-devel] [PATCH 2/2] tui: verify email with basic regex

Maximiliano Sandoval m.sandoval at proxmox.com
Wed Jun 21 14:45:34 CEST 2023


Note that the HTML5 standard [1] suggests 

    /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

as a regex, I am not sure whats the difference but it might be worth it to check if there is any relevant difference. This is used by the validator crate [2] for example.

[1] https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
[2] https://docs.rs/validator/latest/validator/fn.validate_email.html

> On 21.06.2023 14:30 CEST Dominik Csapak <d.csapak at proxmox.com> wrote:
> 
>  
> regex copied from perl gui installer
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> this needs librust-regex-dev as build-dependency
>  proxmox-tui-installer/Cargo.toml  | 1 +
>  proxmox-tui-installer/src/main.rs | 8 ++++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml
> index 9d57b5b..5a50c69 100644
> --- a/proxmox-tui-installer/Cargo.toml
> +++ b/proxmox-tui-installer/Cargo.toml
> @@ -11,5 +11,6 @@ homepage = "https://www.proxmox.com"
>  cursive = { version = "0.20.0", default-features = false, features = ["termion-backend"] }
>  serde = { version = "1.0", features = ["derive"] }
>  serde_json = "1.0"
> +regex = "1.7"
>  
>  proxmox-sys = "0.5.0"
> diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
> index 77cfb63..2d048f0 100644
> --- a/proxmox-tui-installer/src/main.rs
> +++ b/proxmox-tui-installer/src/main.rs
> @@ -25,6 +25,8 @@ use cursive::{
>      Cursive, CursiveRunnable, ScreenId, View, XY,
>  };
>  
> +use regex::Regex;
> +
>  use proxmox_sys::linux::procfs;
>  
>  mod options;
> @@ -484,12 +486,18 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView {
>                      .get_value::<EditView, _>(2)
>                      .ok_or("failed to retrieve email")?;
>  
> +                let email_regex =
> +                    Regex::new(r"^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$")
> +                        .unwrap();
> +
>                  if root_password.len() < 5 {
>                      Err("password too short")
>                  } else if root_password != confirm_password {
>                      Err("passwords do not match")
>                  } else if email == "mail at example.invalid" {
>                      Err("invalid email address")
> +                } else if !email_regex.is_match(&email) {
> +                    Err("Email does not look like a valid address (user at domain.tld)")
>                  } else {
>                      Ok(PasswordOptions {
>                          root_password,
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel





More information about the pve-devel mailing list