From 4d59dfb1c619ebec44243acc7f21dc3edb9feb3b Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 6 Oct 2023 12:58:02 +0200 Subject: [PATCH] Fix some remote posts getting truncated (#27307) --- .../mastodon/components/__tests__/hashtag_bar.tsx | 15 +++++++++++++++ .../mastodon/components/hashtag_bar.tsx | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/components/__tests__/hashtag_bar.tsx b/app/javascript/mastodon/components/__tests__/hashtag_bar.tsx index 1856b7109e..b7225fc92e 100644 --- a/app/javascript/mastodon/components/__tests__/hashtag_bar.tsx +++ b/app/javascript/mastodon/components/__tests__/hashtag_bar.tsx @@ -45,6 +45,21 @@ describe('computeHashtagBarForStatus', () => { ); }); + it('does not truncate the contents when the last child is a text node', () => { + const status = createStatus( + 'this is a #test. Some more text', + ['test'], + ); + + const { hashtagsInBar, statusContentProps } = + computeHashtagBarForStatus(status); + + expect(hashtagsInBar).toEqual([]); + expect(statusContentProps.statusContent).toMatchInlineSnapshot( + `"this is a #test. Some more text"`, + ); + }); + it('extract tags from the last line', () => { const status = createStatus( '

Simple text

#hashtag

', diff --git a/app/javascript/mastodon/components/hashtag_bar.tsx b/app/javascript/mastodon/components/hashtag_bar.tsx index d45a6e20eb..91fa922198 100644 --- a/app/javascript/mastodon/components/hashtag_bar.tsx +++ b/app/javascript/mastodon/components/hashtag_bar.tsx @@ -109,7 +109,7 @@ export function computeHashtagBarForStatus(status: StatusLike): { const lastChild = template.content.lastChild; - if (!lastChild) return defaultResult; + if (!lastChild || lastChild.nodeType === Node.TEXT_NODE) return defaultResult; template.content.removeChild(lastChild); const contentWithoutLastLine = template;