From 4d854c8054c7170a228e1d9cfe83083869464222 Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 20 Feb 2024 18:08:14 -0800 Subject: [PATCH] Allow raw HTML on web with a flag --- src/libs/ReportUtils.ts | 3 ++- src/libs/shouldAllowRawHTMLMessages/index.native.ts | 3 +++ src/libs/shouldAllowRawHTMLMessages/index.ts | 5 +++++ src/types/global.d.ts | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/libs/shouldAllowRawHTMLMessages/index.native.ts create mode 100644 src/libs/shouldAllowRawHTMLMessages/index.ts diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 006c85ce12c7..e2b6a14e2e08 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -62,6 +62,7 @@ import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import * as PolicyUtils from './PolicyUtils'; import type {LastVisibleMessage} from './ReportActionsUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; +import shouldAllowRawHTMLMessages from './shouldAllowRawHTMLMessages'; import * as TransactionUtils from './TransactionUtils'; import * as Url from './Url'; import * as UserUtils from './UserUtils'; @@ -2697,7 +2698,7 @@ function hasReportNameError(report: OnyxEntry): boolean { */ function getParsedComment(text: string): string { const parser = new ExpensiMark(); - return text.length <= CONST.MAX_MARKUP_LENGTH ? parser.replace(text) : lodashEscape(text); + return text.length <= CONST.MAX_MARKUP_LENGTH ? parser.replace(text, {shouldEscapeText: !shouldAllowRawHTMLMessages()}) : lodashEscape(text); } function getReportDescriptionText(report: Report): string { diff --git a/src/libs/shouldAllowRawHTMLMessages/index.native.ts b/src/libs/shouldAllowRawHTMLMessages/index.native.ts new file mode 100644 index 000000000000..db886f7f6fe8 --- /dev/null +++ b/src/libs/shouldAllowRawHTMLMessages/index.native.ts @@ -0,0 +1,3 @@ +export default function () { + return false; +} diff --git a/src/libs/shouldAllowRawHTMLMessages/index.ts b/src/libs/shouldAllowRawHTMLMessages/index.ts new file mode 100644 index 000000000000..577dc3055441 --- /dev/null +++ b/src/libs/shouldAllowRawHTMLMessages/index.ts @@ -0,0 +1,5 @@ +window.shouldAllowRawHTMLMessages = false; + +export default function () { + return window.shouldAllowRawHTMLMessages; +} diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 03446e813949..911f1ea5f281 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -30,4 +30,5 @@ declare module '*.lottie' { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface Window { setSupportToken: (token: string, email: string, accountID: number) => void; + shouldAllowRawHTMLMessages: boolean; }