Skip to content

Commit d91ed96

Browse files
authored
Merge pull request #88767 from wildan-m/wildan/87519-split-details-html-tags
Fix HTML tags showing in Split details page description
2 parents 4aa41e4 + fd0ea27 commit d91ed96

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/components/MoneyRequestConfirmationList/sections/DescriptionField.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import useOnyx from '@hooks/useOnyx';
1010
import useThemeStyles from '@hooks/useThemeStyles';
1111
import {setMoneyRequestDescription} from '@libs/actions/IOU';
1212
import Navigation from '@libs/Navigation/Navigation';
13+
import Parser from '@libs/Parser';
1314
import {getDescription, hasReceipt} from '@libs/TransactionUtils';
1415
import variables from '@styles/variables';
1516
import {setDraftSplitTransaction} from '@userActions/IOU/Split';
@@ -53,7 +54,9 @@ function DescriptionField({
5354

5455
const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`);
5556

56-
const iouComment = getDescription(transaction);
57+
// `getDescription` returns raw `transaction.comment.comment`, which can be HTML for saved transactions.
58+
// We normalize to markdown so both the read-only and editable inputs receive a consistent format.
59+
const iouComment = Parser.htmlToMarkdown(getDescription(transaction));
5760

5861
const contextMenuStateValue = {
5962
anchor: null,

tests/unit/ParserTest.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,28 @@ describe('Parser', () => {
2424
expect(Parser.isHTML('<>')).toBe(false);
2525
});
2626
});
27+
28+
describe('htmlToMarkdown', () => {
29+
// These cases pin the contract relied on by DescriptionField.tsx, where the description of a saved
30+
// transaction is stored as HTML (because `getParsedComment()` runs ExpensiMark at save time) and must
31+
// be normalized back to markdown before being handed to the `shouldParseTitle` MenuItem and the
32+
// `type="markdown"` TextInput. Without this normalization, the Split details page renders raw `<a>`
33+
// tags as visible text — see https://github.com/Expensify/App/issues/87519.
34+
test('converts an autolinked URL anchor back to a markdown link', () => {
35+
expect(Parser.htmlToMarkdown('<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>')).toBe('[google.com](https://google.com)');
36+
});
37+
38+
test('converts ExpensiMark-emitted bold tags back to markdown asterisks', () => {
39+
expect(Parser.htmlToMarkdown('<strong>hello</strong> world')).toBe('*hello* world');
40+
});
41+
42+
test('is a no-op for plain text descriptions used by draft transactions', () => {
43+
expect(Parser.htmlToMarkdown('lunch')).toBe('lunch');
44+
expect(Parser.htmlToMarkdown('google.com')).toBe('google.com');
45+
});
46+
47+
test('returns an empty string for an empty input', () => {
48+
expect(Parser.htmlToMarkdown('')).toBe('');
49+
});
50+
});
2751
});

0 commit comments

Comments
 (0)