~vpzom/lotide

6dabb9f50d6138214706066fb64862f5fc7b5b5f — Colin Reeder 23 days ago 89f94cd
Add ugc to link rel (#152)
M src/apub_util/mod.rs => src/apub_util/mod.rs +2 -2
@@ 910,7 910,7 @@ pub fn post_to_ap(
    ) -> Result<(), crate::Error> {
        if let Some(html) = post.content_html {
            props
                .set_content(ammonia::clean(&html))
                .set_content(crate::clean_html(&html))
                .set_media_type(mime::TEXT_HTML);

            if let Some(md) = post.content_markdown {


@@ 1052,7 1052,7 @@ pub fn local_comment_to_ap(
    let mut obj = activitystreams::object::ApObject::new(obj);

    if let Some(html) = &comment.content_html {
        obj.set_content(ammonia::clean(&html))
        obj.set_content(crate::clean_html(&html))
            .set_media_type(mime::TEXT_HTML);

        if let Some(md) = &comment.content_markdown {

M src/main.rs => src/main.rs +13 -0
@@ 681,6 681,19 @@ pub fn render_markdown(src: &str) -> String {
    output
}

lazy_static::lazy_static! {
    static ref SANITIZER: ammonia::Builder<'static> = {
        let mut builder = ammonia::Builder::default();
        builder.link_rel(Some("ugc noopener noreferrer"));

        builder
    };
}

pub fn clean_html(src: &str) -> String {
    SANITIZER.clean(src).to_string()
}

pub fn on_local_community_add_post(
    community: CommunityLocalID,
    post_local_id: PostLocalID,

M src/routes/api/comments.rs => src/routes/api/comments.rs +1 -1
@@ 103,7 103,7 @@ async fn route_unstable_comments_get(
                        content_text: row.get::<_, Option<&str>>(2).map(Cow::Borrowed),
                        content_html_safe: row
                            .get::<_, Option<&str>>(5)
                            .map(|html| ammonia::clean(&html)),
                            .map(|html| crate::clean_html(&html)),
                    },

                    attachments: match ctx.process_attachments_inner(

M src/routes/api/communities.rs => src/routes/api/communities.rs +2 -2
@@ 42,7 42,7 @@ fn get_community_description_fields<'a>(
        Some(description_html) => (
            description_html,
            None,
            Some(ammonia::clean(description_html)),
            Some(crate::clean_html(description_html)),
        ),
        None => (description_text, Some(description_text), None),
    }


@@ 799,7 799,7 @@ async fn route_unstable_communities_posts_list(
                title,
                href: ctx.process_href_opt(href, id),
                content_text,
                content_html_safe: content_html.map(|html| ammonia::clean(&html)),
                content_html_safe: content_html.map(|html| crate::clean_html(&html)),
                author: author.as_ref(),
                created: &created.to_rfc3339(),
                community: &community,

M src/routes/api/mod.rs => src/routes/api/mod.rs +2 -2
@@ 959,7 959,7 @@ async fn get_comments_replies<'a>(
                    base: RespMinimalCommentInfo {
                        id,
                        content_text: content_text.map(From::from),
                        content_html_safe: content_html.map(|html| ammonia::clean(&html)),
                        content_html_safe: content_html.map(|html| crate::clean_html(&html)),
                    },

                    attachments: match ctx


@@ 1096,7 1096,7 @@ async fn handle_common_posts_list(
                title,
                href: ctx.process_href_opt(href, id),
                content_text,
                content_html_safe: content_html.map(|html| ammonia::clean(&html)),
                content_html_safe: content_html.map(|html| crate::clean_html(&html)),
                author: author.as_ref(),
                created: &created.to_rfc3339(),
                community: &community,

M src/routes/api/posts.rs => src/routes/api/posts.rs +2 -2
@@ 102,7 102,7 @@ async fn get_post_comments<'a>(
                    base: RespMinimalCommentInfo {
                        id,
                        content_text: content_text.map(From::from),
                        content_html_safe: content_html.map(|html| ammonia::clean(&html)),
                        content_html_safe: content_html.map(|html| crate::clean_html(&html)),
                    },

                    attachments: match ctx


@@ 527,7 527,7 @@ async fn route_unstable_posts_get(
                title,
                href: ctx.process_href_opt(href, post_id),
                content_text,
                content_html_safe: content_html.map(|html| ammonia::clean(&html)),
                content_html_safe: content_html.map(|html| crate::clean_html(&html)),
                author: author.as_ref(),
                created: &created.to_rfc3339(),
                community: &community,

M src/routes/api/users.rs => src/routes/api/users.rs +4 -4
@@ 438,7 438,7 @@ async fn route_unstable_users_notifications_list(
                                content_text: row.get::<_, Option<_>>(3).map(Cow::Borrowed),
                                content_html_safe: row
                                    .get::<_, Option<&str>>(4)
                                    .map(|html| ammonia::clean(&html)),
                                    .map(|html| crate::clean_html(&html)),
                            };
                            let post = RespMinimalPostInfo {
                                id: PostLocalID(post_id),


@@ 464,7 464,7 @@ async fn route_unstable_users_notifications_list(
                                content_text: row.get::<_, Option<_>>(3).map(Cow::Borrowed),
                                content_html_safe: row
                                    .get::<_, Option<&str>>(4)
                                    .map(|html| ammonia::clean(&html)),
                                    .map(|html| crate::clean_html(&html)),
                            };
                            let parent_id = CommentLocalID(parent_id);
                            let post =


@@ 568,7 568,7 @@ async fn route_unstable_users_get(
        Some(description_html) => (
            description_html,
            None,
            Some(ammonia::clean(description_html)),
            Some(crate::clean_html(description_html)),
        ),
        None => {
            let description_text: &str = row.get(3);


@@ 668,7 668,7 @@ async fn route_unstable_users_things_list(
                        content_text: row.get::<_, Option<_>>(2).map(Cow::Borrowed),
                        content_html_safe: row
                            .get::<_, Option<&str>>(3)
                            .map(|html| ammonia::clean(&html)),
                            .map(|html| crate::clean_html(&html)),
                    },
                    created,
                    post: RespMinimalPostInfo {