]> Untitled Git - lemmy.git/commitdiff
Empty post bodies (#2050)
authorDessalines <dessalines@users.noreply.github.com>
Fri, 21 Jan 2022 13:38:01 +0000 (08:38 -0500)
committerGitHub <noreply@github.com>
Fri, 21 Jan 2022 13:38:01 +0000 (13:38 +0000)
* Cleaning optional post bodies. Fixes #2039

* Only trim once.

* Using .map() instead.

* Revert "Using .map() instead."

This reverts commit a2f49072095e0c0622c4a7d041dcea81e11fe1dc.

crates/utils/src/utils.rs

index 2b28ae0eaa3dfe847574e8b0dc409a8097a9383e..a1fefffe84a3ff958956b3c57012e7877774b71b 100644 (file)
@@ -176,7 +176,16 @@ pub fn clean_url_params(mut url: Url) -> Url {
 }
 
 pub fn clean_optional_text(text: &Option<String>) -> Option<String> {
-  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)]