From 6f5ca5f4524bec3cda2990f352080f08524e578b Mon Sep 17 00:00:00 2001 From: Awiteb Date: Wed, 24 Jul 2024 11:03:42 +0300 Subject: [PATCH] fix: Reject empty string field value Signed-off-by: Awiteb --- src/cli/add_command.rs | 23 +++++++++++++++++++++++ src/errors.rs | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/cli/add_command.rs b/src/cli/add_command.rs index e616a50..1b02d0e 100644 --- a/src/cli/add_command.rs +++ b/src/cli/add_command.rs @@ -92,6 +92,29 @@ impl LprsCommand for Add { ))); } } + if self + .password + .as_ref() + .is_some_and(|p| p.as_ref().is_some_and(|p| p.is_empty())) + || self.vault_info.name.is_empty() + || self + .vault_info + .username + .as_ref() + .is_some_and(|u| u.is_empty()) + || self + .vault_info + .service + .as_ref() + .is_some_and(|s| s.is_empty()) + || self.vault_info.note.as_ref().is_some_and(|n| n.is_empty()) + || self + .custom_fields + .iter() + .any(|(k, v)| k.is_empty() || v.is_empty()) + { + return Err(LprsError::EmptyValue); + } if self .custom_fields .iter() diff --git a/src/errors.rs b/src/errors.rs index e5e2253..1d22cb6 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -44,6 +44,8 @@ pub enum Error { custom fields {0}" )] ReservedPrefix(&'static str), + #[error("Invalid Field Value: Field value cannot be empty")] + EmptyValue, #[error("Base32 Error: {0}")] Base32(String), #[error("{0}")] -- 2.45.2