From: Dessalines Date: Fri, 21 Jan 2022 13:38:01 +0000 (-0500) Subject: Empty post bodies (#2050) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7B%27/README.md?a=commitdiff_plain;h=16271b0a4c88fd8341ac53e6c0750989e822e339;p=lemmy.git Empty post bodies (#2050) * Cleaning optional post bodies. Fixes #2039 * Only trim once. * Using .map() instead. * Revert "Using .map() instead." This reverts commit a2f49072095e0c0622c4a7d041dcea81e11fe1dc. --- diff --git a/crates/utils/src/utils.rs b/crates/utils/src/utils.rs index 2b28ae0e..a1fefffe 100644 --- a/crates/utils/src/utils.rs +++ b/crates/utils/src/utils.rs @@ -176,7 +176,16 @@ pub fn clean_url_params(mut url: Url) -> Url { } pub fn clean_optional_text(text: &Option) -> Option { - text.as_ref().map(|t| t.trim().to_string()) + if let Some(text) = text { + let trimmed = text.trim(); + if trimmed.is_empty() { + None + } else { + Some(trimmed.to_owned()) + } + } else { + None + } } #[cfg(test)]