From d09d2d05d19ea5f8952d27ee4f025c4f995bd39f Mon Sep 17 00:00:00 2001 From: Tommaso Casaburi Date: Wed, 3 Jun 2026 13:49:35 +0700 Subject: [PATCH] fix(fortune): scope s5s fortune markup (#1150) * fix(markdown): scope fortune markup to fortune boards * fix(fortune): store fortune output as bbcode * fix(fortune): keep legacy fortune rendering * fix(tests): resolve catalog button mock merge * fix(fortune): validate hidden fortune length --- .../__tests__/challenge-modal.test.tsx | 24 ++++++ .../challenge-modal/challenge-modal.tsx | 6 +- .../__tests__/comment-content.test.tsx | 21 +++++ .../comment-content/comment-content.tsx | 78 +++++++++--------- .../markdown/__tests__/markdown.test.tsx | 54 +++++++++++-- src/components/markdown/markdown.tsx | 80 +++++++++++++++---- .../post-form/__tests__/post-form.test.tsx | 37 ++++++++- src/components/post-form/post-form.tsx | 9 ++- .../__tests__/reply-modal.test.tsx | 38 ++++++++- src/components/reply-modal/reply-modal.tsx | 21 +++-- .../__tests__/use-delete-failed-post.test.tsx | 1 + .../__tests__/post-options-utils.test.ts | 49 +++++++++++- src/lib/utils/challenge-utils.ts | 52 +++++++++++- src/lib/utils/post-options-utils.ts | 41 ++++++++-- .../__tests__/interaction-stores.test.ts | 18 +++++ src/stores/use-challenges-store.ts | 3 +- 16 files changed, 439 insertions(+), 93 deletions(-) diff --git a/src/components/challenge-modal/__tests__/challenge-modal.test.tsx b/src/components/challenge-modal/__tests__/challenge-modal.test.tsx index 50c494e2..bdde3b4e 100644 --- a/src/components/challenge-modal/__tests__/challenge-modal.test.tsx +++ b/src/components/challenge-modal/__tests__/challenge-modal.test.tsx @@ -226,6 +226,30 @@ describe('ChallengeModal', () => { expect(testState.removeChallengeMock).toHaveBeenCalledOnce(); }); + it('redacts generated fortune BBCode from challenge publication details', async () => { + const publication = { + ...createPublication(), + content: 'body[fortune color=#fd4d32]Excellent Luck[/fortune]', + }; + testState.publicationPreview = 'body'; + testState.publicationType = 'post'; + testState.challenges = [ + createStoredChallenge( + { + challenge: '2 + 2', + type: 'text/plain', + }, + publication, + ), + ]; + + await renderModal(); + + expect(container.querySelector('textarea')?.value).toBe('body'); + expect(container.textContent).not.toContain('Excellent Luck'); + expect(container.textContent).not.toContain('[fortune'); + }); + it('supports multi-step image challenges with next and previous navigation', async () => { const publication = createPublication(); testState.challenges = [ diff --git a/src/components/challenge-modal/challenge-modal.tsx b/src/components/challenge-modal/challenge-modal.tsx index d1fd7ad6..6a5ffafb 100644 --- a/src/components/challenge-modal/challenge-modal.tsx +++ b/src/components/challenge-modal/challenge-modal.tsx @@ -2,6 +2,7 @@ import { useRef, useState, useEffect, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { Challenge as ChallengeType, useAccount, useComment } from '@bitsocial/bitsocial-react-hooks'; import { getPublicationPreview, getPublicationType, getVotePreview } from '../../lib/utils/challenge-utils'; +import { stripGeneratedFortuneMarkup } from '../../lib/utils/post-options-utils'; import useIsMobile from '../../hooks/use-is-mobile'; import useChallengesStore from '../../stores/use-challenges-store'; import useTrustedBoardUrlPermissionsStore from '../../stores/use-trusted-board-url-permissions-store'; @@ -325,6 +326,7 @@ const Challenge = ({ challenge, closeModal, abandonModal }: ChallengeProps) => { const votePreview = getVotePreview(publication); const { author, content, link, title, parentCid, shortCommunityAddress, communityAddress } = publication || {}; + const visibleContent = content ? stripGeneratedFortuneMarkup(content) : ''; const { displayName } = author || {}; const parentAddress = useParentAddress(parentCid); const community = shortCommunityAddress || communityAddress; @@ -493,9 +495,9 @@ const Challenge = ({ challenge, closeModal, abandonModal }: ChallengeProps) => { )} - {content && ( + {visibleContent && (
-