From 0c78040ade678e7d631493e2edbb5ac15a4e4c0b Mon Sep 17 00:00:00 2001 From: Jan Danielsson Date: Fri, 1 Dec 2023 16:26:40 +0100 Subject: [PATCH] Touchup of field length validation error messagtes; add special case for fixed length fields and change the phrasing when a length has a lower bound only. --- core/lib/src/form/error.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/lib/src/form/error.rs b/core/lib/src/form/error.rs index b6f3c506..0eb6434e 100644 --- a/core/lib/src/form/error.rs +++ b/core/lib/src/form/error.rs @@ -817,8 +817,15 @@ impl fmt::Display for ErrorKind<'_> { (None, Some(k)) if *k < 1024 => write!(f, "length cannot exceed {}", k)?, (None, Some(k)) => write!(f, "size must not exceed {}", ByteUnit::from(*k))?, (Some(1), None) => write!(f, "cannot be empty")?, - (Some(k), None) if *k < 1024 => write!(f, "expected at least {}", k)?, + (Some(k), None) if *k < 1024 => write!(f, "length expected to be at least {}", k)?, (Some(k), None) => write!(f, "size must be at least {}", ByteUnit::from(*k))?, + (Some(i), Some(j)) if *i == *j && *i < 1024 => { + write!(f, "length must be {}", i)?; + } + (Some(i), Some(j)) if *i == *j => { + let i = ByteUnit::from(*i); + write!(f, "length must be {}", i)?; + } (Some(i), Some(j)) if *i < 1024 && *j < 1024 => { write!(f, "length must be between {} and {}", i, j)?; }