diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index ff12874dd5..6f597ee772 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -313,7 +313,7 @@ Helpers.generateTitle = (html) => { // Try the first paragraph-like element const match = html.match(titleRegex); - if (match) { + if (match && match.index === 0) { title = match[2]; } @@ -332,6 +332,8 @@ Helpers.generateTitle = (html) => { .reduce((memo, cur, idx, sentences) => { if (idx % 2) { memo.push(`${sentences[idx - 1]}${cur}`); + } else if (idx === sentences.length - 1) { + memo.push(cur); } return memo; diff --git a/test/activitypub.js b/test/activitypub.js index 89594d7f16..44557e0656 100644 --- a/test/activitypub.js +++ b/test/activitypub.js @@ -133,6 +133,12 @@ describe('ActivityPub integration', () => { // Content after line breaks can be discarded ['

Intro text
example.org/

more text

', 'Intro text'], + // HTML without outer wrapping element + ['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'], + + // Two sentences with punctuation + ['Lorem ipsum. Dolor sit amet.', 'Lorem ipsum.'], + // Additional tests? // ['', ''], ]);