From: Dessalines Date: Thu, 22 Oct 2020 17:23:25 +0000 (-0500) Subject: Fix invalid url error when removing icons. Fixes #1219 X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/readmes/%7B%7D/%22%7Burl%7D/%24%7Bargs.pageFn.jump%20n%7D?a=commitdiff_plain;h=18111629fa3b30cb499be9decadc7be9366db5d6;p=lemmy.git Fix invalid url error when removing icons. Fixes #1219 --- diff --git a/lemmy_api/src/community.rs b/lemmy_api/src/community.rs index 8b1a43bc..4149053f 100644 --- a/lemmy_api/src/community.rs +++ b/lemmy_api/src/community.rs @@ -140,8 +140,8 @@ impl Perform for CreateCommunity { let icon = diesel_option_overwrite(&data.icon); let banner = diesel_option_overwrite(&data.banner); - check_optional_url(&data.icon)?; - check_optional_url(&data.banner)?; + check_optional_url(&icon)?; + check_optional_url(&banner)?; // When you create a community, make sure the user becomes a moderator and a follower let keypair = generate_actor_keypair()?; @@ -240,8 +240,8 @@ impl Perform for EditCommunity { let icon = diesel_option_overwrite(&data.icon); let banner = diesel_option_overwrite(&data.banner); - check_optional_url(&data.icon)?; - check_optional_url(&data.banner)?; + check_optional_url(&icon)?; + check_optional_url(&banner)?; let community_form = CommunityForm { name: read_community.name, diff --git a/lemmy_api/src/lib.rs b/lemmy_api/src/lib.rs index 21be1819..0f0367cf 100644 --- a/lemmy_api/src/lib.rs +++ b/lemmy_api/src/lib.rs @@ -100,8 +100,8 @@ pub(in crate) async fn check_community_ban( } } -pub(in crate) fn check_optional_url(item: &Option) -> Result<(), LemmyError> { - if let Some(item) = &item { +pub(in crate) fn check_optional_url(item: &Option>) -> Result<(), LemmyError> { + if let Some(Some(item)) = &item { if Url::parse(item).is_err() { return Err(APIError::err("invalid_url").into()); } diff --git a/lemmy_api/src/post.rs b/lemmy_api/src/post.rs index c013cbbd..755b98af 100644 --- a/lemmy_api/src/post.rs +++ b/lemmy_api/src/post.rs @@ -59,7 +59,7 @@ impl Perform for CreatePost { check_community_ban(user.id, data.community_id, context.pool()).await?; - check_optional_url(&data.url)?; + check_optional_url(&Some(data.url.to_owned()))?; // Fetch Iframely and pictrs cached image let (iframely_title, iframely_description, iframely_html, pictrs_thumbnail) = diff --git a/lemmy_api/src/user.rs b/lemmy_api/src/user.rs index 58d119a6..02accc87 100644 --- a/lemmy_api/src/user.rs +++ b/lemmy_api/src/user.rs @@ -349,8 +349,8 @@ impl Perform for SaveUserSettings { let matrix_user_id = diesel_option_overwrite(&data.matrix_user_id); // Check to make sure the avatar and banners are urls - check_optional_url(&data.avatar)?; - check_optional_url(&data.banner)?; + check_optional_url(&avatar)?; + check_optional_url(&banner)?; if let Some(Some(bio)) = &bio { if bio.chars().count() > 300 {