Trim form strings by default

This commit is contained in:
Mo 2023-02-26 12:32:06 +01:00
parent a5470ae857
commit 423dcb6914
3 changed files with 5 additions and 9 deletions

View file

@ -45,9 +45,10 @@ impl ContactForm {
.parse() .parse()
.context("Failed to parse the submitted id!")?; .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| { let mut remove = |key| {
map.remove(key) map.remove(key)
.map(|v| v.trim().to_string())
.with_context(|| format!("{} missing in the submitted form!", key)) .with_context(|| format!("{} missing in the submitted form!", key))
}; };

View file

@ -69,7 +69,7 @@ impl Mailer {
persistent_field_contents: &PersistentFieldContents, persistent_field_contents: &PersistentFieldContents,
config: &StateConfig, config: &StateConfig,
) -> Result<()> { ) -> 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 subject = config.strings.message_from.clone() + &name;
let reply_to = Mailbox::new( let reply_to = Mailbox::new(
Some(name), Some(name),
@ -90,12 +90,7 @@ impl Mailer {
.custom_fields .custom_fields
.iter() .iter()
.map(|field| &field.label) .map(|field| &field.label)
.zip( .zip(persistent_field_contents.custom.iter())
persistent_field_contents
.custom
.iter()
.map(|content| content.trim()),
)
.map(|(label, content)| format!("{label}:\n{content}\n\n\n")) .map(|(label, content)| format!("{label}:\n{content}\n\n\n"))
.fold(default_fields_content, |acc, s| acc + &s); .fold(default_fields_content, |acc, s| acc + &s);

View file

@ -85,7 +85,7 @@ pub async fn submit(
let right_captcha_answer = captcha_solutions let right_captcha_answer = captcha_solutions
.lock() .lock()
.unwrap() .unwrap()
.check_answer(form.id, form.captcha_answer.trim()); .check_answer(form.id, &form.captcha_answer);
if !right_captcha_answer { if !right_captcha_answer {
info!("Wrong CAPTCHA"); info!("Wrong CAPTCHA");