From cd3a636b7fe7fa8272c3f15a5e4a028e59be081b Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 6 Oct 2023 12:58:02 +0200 Subject: [PATCH] [Glitch] Fix some remote posts getting truncated Port 4d59dfb1c619ebec44243acc7f21dc3edb9feb3b to glitch-soc Signed-off-by: Claire --- .../glitch/components/__tests__/hashtag_bar.tsx | 15 +++++++++++++++ .../flavours/glitch/components/hashtag_bar.tsx | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/components/__tests__/hashtag_bar.tsx b/app/javascript/flavours/glitch/components/__tests__/hashtag_bar.tsx index 1856b7109e..b7225fc92e 100644 --- a/app/javascript/flavours/glitch/components/__tests__/hashtag_bar.tsx +++ b/app/javascript/flavours/glitch/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/flavours/glitch/components/hashtag_bar.tsx b/app/javascript/flavours/glitch/components/hashtag_bar.tsx index d45a6e20eb..91fa922198 100644 --- a/app/javascript/flavours/glitch/components/hashtag_bar.tsx +++ b/app/javascript/flavours/glitch/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;