diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index b3c641e0c3..380823fa31 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -757,17 +757,25 @@ Mocks.notes.public = async (post) => { attachment: normalizeAttachment(noteAttachment), }; - const sentences = tokenizer.sentences(post.content, { sanitize: true }); + const sentences = tokenizer.sentences(post.content, { newline_boundaries: true }); // Append sentences to summary until it contains just under 500 characters of content const limit = 500; + let remaining = limit; summary = sentences.reduce((memo, sentence) => { - const remaining = limit - memo.length; - if (sentence.length < remaining) { + const clean = sanitize(sentence, { + allowedTags: [], + allowedAttributes: {}, + }); + remaining = remaining - clean.length; + if (remaining > 0) { memo += ` ${sentence}`; } return memo; }, ''); + + // Final sanitization to clean up tags + summary = posts.sanitize(summary); } let context = await posts.getPostField(post.pid, 'context'); diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index ce9371fd26..5739d25ecf 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -156,7 +156,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { // mainPid ok to leave as-is if (!title) { - const sentences = tokenizer.sentences(content || sourceContent, { sanitize: true }); + const sentences = tokenizer.sentences(content || sourceContent, { sanitize: true, newline_boundaries: true }); title = sentences.shift(); }