mirror of https://github.com/LemmyNet/lemmy.git
Cleaning optional post bodies. Fixes #2039
parent
eea3308906
commit
194269fd3c
|
@ -26,7 +26,13 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
request::fetch_site_data,
|
request::fetch_site_data,
|
||||||
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
|
utils::{
|
||||||
|
check_slurs,
|
||||||
|
check_slurs_opt,
|
||||||
|
clean_optional_text,
|
||||||
|
clean_url_params,
|
||||||
|
is_valid_post_title,
|
||||||
|
},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
|
@ -72,7 +78,7 @@ impl PerformCrud for CreatePost {
|
||||||
let post_form = PostForm {
|
let post_form = PostForm {
|
||||||
name: data.name.trim().to_owned(),
|
name: data.name.trim().to_owned(),
|
||||||
url: data_url.map(|u| clean_url_params(u.to_owned()).into()),
|
url: data_url.map(|u| clean_url_params(u.to_owned()).into()),
|
||||||
body: data.body.to_owned(),
|
body: clean_optional_text(&data.body),
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
creator_id: local_user_view.person.id,
|
creator_id: local_user_view.person.id,
|
||||||
nsfw: data.nsfw,
|
nsfw: data.nsfw,
|
||||||
|
|
|
@ -18,7 +18,7 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
request::fetch_site_data,
|
request::fetch_site_data,
|
||||||
utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
|
utils::{check_slurs_opt, clean_optional_text, clean_url_params, is_valid_post_title},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
|
@ -79,7 +79,7 @@ impl PerformCrud for EditPost {
|
||||||
community_id: orig_post.community_id,
|
community_id: orig_post.community_id,
|
||||||
name: data.name.to_owned().unwrap_or(orig_post.name),
|
name: data.name.to_owned().unwrap_or(orig_post.name),
|
||||||
url: data_url.map(|u| clean_url_params(u.to_owned()).into()),
|
url: data_url.map(|u| clean_url_params(u.to_owned()).into()),
|
||||||
body: data.body.to_owned(),
|
body: clean_optional_text(&data.body),
|
||||||
nsfw: data.nsfw,
|
nsfw: data.nsfw,
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
embed_title,
|
embed_title,
|
||||||
|
|
|
@ -161,7 +161,7 @@ where
|
||||||
#[allow(clippy::to_string_in_display)]
|
#[allow(clippy::to_string_in_display)]
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
// Use to_string here because Url.display is not useful for us
|
// Use to_string here because Url.display is not useful for us
|
||||||
write!(f, "{}", self.0.to_string())
|
write!(f, "{}", self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,11 +97,7 @@ async fn get_feed_data(
|
||||||
let mut channel_builder = ChannelBuilder::default();
|
let mut channel_builder = ChannelBuilder::default();
|
||||||
channel_builder
|
channel_builder
|
||||||
.namespaces(RSS_NAMESPACE.to_owned())
|
.namespaces(RSS_NAMESPACE.to_owned())
|
||||||
.title(&format!(
|
.title(&format!("{} - {}", site_view.site.name, listing_type))
|
||||||
"{} - {}",
|
|
||||||
site_view.site.name,
|
|
||||||
listing_type.to_string()
|
|
||||||
))
|
|
||||||
.link(context.settings().get_protocol_and_hostname())
|
.link(context.settings().get_protocol_and_hostname())
|
||||||
.items(items);
|
.items(items);
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,18 @@ pub fn clean_url_params(mut url: Url) -> Url {
|
||||||
url
|
url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clean_optional_text(text: &Option<String>) -> Option<String> {
|
||||||
|
if let Some(text) = text {
|
||||||
|
if text.trim().is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(text.trim().to_owned())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::{clean_url_params, is_valid_post_title};
|
use crate::utils::{clean_url_params, is_valid_post_title};
|
||||||
|
|
Loading…
Reference in New Issue