From f71b7943f96af403cbdc38d2455fa89d363fae08 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 1856b7109..b7225fc92 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 d45a6e20e..91fa92219 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;