diff --git a/core/lib/src/form/from_form_field.rs b/core/lib/src/form/from_form_field.rs index 756677ab..b866300f 100644 --- a/core/lib/src/form/from_form_field.rs +++ b/core/lib/src/form/from_form_field.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr}; use std::num::{ NonZeroIsize, NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, @@ -312,14 +313,29 @@ impl<'v> FromFormField<'v> for bool { fn from_value(field: ValueField<'v>) -> Result<'v, Self> { match field.value.as_uncased() { - v if v == "on" || v == "yes" || v == "true" => Ok(true), v if v == "off" || v == "no" || v == "false" => Ok(false), + v if v.is_empty() || v == "on" || v == "yes" || v == "true" => Ok(true), // force a `ParseBoolError` _ => Ok("".parse()?), } } } +#[crate::async_trait] +impl<'v> FromFormField<'v> for Capped> { + fn from_value(field: ValueField<'v>) -> Result<'v, Self> { + let capped = >::from_value(field)?; + Ok(capped.map(|s| s.into())) + } + + async fn from_data(field: DataField<'v, '_>) -> Result<'v, Self> { + let capped = >::from_data(field).await?; + Ok(capped.map(|s| s.into())) + } +} + +impl_strict_from_form_field_from_capped!(Cow<'v, str>); + macro_rules! impl_with_parse { ($($T:ident),+ $(,)?) => ($( impl<'v> FromFormField<'v> for $T {