From 423dcb69143048fbce5f01daa250be93509be3b3 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sun, 26 Feb 2023 12:32:06 +0100 Subject: [PATCH] Trim form strings by default --- src/forms.rs | 3 ++- src/mailer.rs | 9 ++------- src/routes.rs | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/forms.rs b/src/forms.rs index 25d6ef1..a3acba0 100644 --- a/src/forms.rs +++ b/src/forms.rs @@ -45,9 +45,10 @@ impl ContactForm { .parse() .context("Failed to parse the submitted id!")?; - // Remove an item with the given key from the map. + // Remove a trimmed item with the given key from the map. let mut remove = |key| { map.remove(key) + .map(|v| v.trim().to_string()) .with_context(|| format!("{} missing in the submitted form!", key)) }; diff --git a/src/mailer.rs b/src/mailer.rs index 1cd44b0..cf3e0dc 100644 --- a/src/mailer.rs +++ b/src/mailer.rs @@ -69,7 +69,7 @@ impl Mailer { persistent_field_contents: &PersistentFieldContents, config: &StateConfig, ) -> Result<()> { - let name = persistent_field_contents.name.trim().to_string(); + let name = persistent_field_contents.name.clone(); let subject = config.strings.message_from.clone() + &name; let reply_to = Mailbox::new( Some(name), @@ -90,12 +90,7 @@ impl Mailer { .custom_fields .iter() .map(|field| &field.label) - .zip( - persistent_field_contents - .custom - .iter() - .map(|content| content.trim()), - ) + .zip(persistent_field_contents.custom.iter()) .map(|(label, content)| format!("{label}:\n{content}\n\n\n")) .fold(default_fields_content, |acc, s| acc + &s); diff --git a/src/routes.rs b/src/routes.rs index e5747b0..cc6a5d4 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -85,7 +85,7 @@ pub async fn submit( let right_captcha_answer = captcha_solutions .lock() .unwrap() - .check_answer(form.id, form.captcha_answer.trim()); + .check_answer(form.id, &form.captcha_answer); if !right_captcha_answer { info!("Wrong CAPTCHA");