From 60d6931b95966af5be1a0700b52d833fb00ef992 Mon Sep 17 00:00:00 2001 From: Eric Han Date: Thu, 11 May 2023 09:40:38 +0800 Subject: [PATCH 1/2] return false if report action is not an attachment --- src/libs/isReportMessageAttachment.js | 3 ++- tests/unit/isReportMessageAttachmentTest.js | 22 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/unit/isReportMessageAttachmentTest.js diff --git a/src/libs/isReportMessageAttachment.js b/src/libs/isReportMessageAttachment.js index e524d5f79f64..852dc924fdbb 100644 --- a/src/libs/isReportMessageAttachment.js +++ b/src/libs/isReportMessageAttachment.js @@ -8,5 +8,6 @@ import CONST from '../CONST'; * @returns {Boolean} */ export default function isReportMessageAttachment({text, html}) { - return text === CONST.ATTACHMENT_MESSAGE_TEXT && html !== CONST.ATTACHMENT_MESSAGE_TEXT; + const regex = new RegExp(` ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="(.+?)"`, 'i'); + return text === CONST.ATTACHMENT_MESSAGE_TEXT && !!html.match(regex); } diff --git a/tests/unit/isReportMessageAttachmentTest.js b/tests/unit/isReportMessageAttachmentTest.js new file mode 100644 index 000000000000..8338513a7e7e --- /dev/null +++ b/tests/unit/isReportMessageAttachmentTest.js @@ -0,0 +1,22 @@ +import isReportMessageAttachment from '../../src/libs/isReportMessageAttachment'; + +describe('isReportMessageAttachment', () => { + it('returns true if a report action is attachment', () => { + const message = { + text: '[Attachment]', + html: '', + }; + expect(isReportMessageAttachment(message)).toBe(true); + }); + + it('returns false if a report action is not attachment', () => { + let message = {text: '[Attachment]', html: '[Attachment]'}; + expect(isReportMessageAttachment(message)).toBe(false); + + message = {text: '[Attachment]', html: '[Attachment]'}; + expect(isReportMessageAttachment(message)).toBe(false); + + message = {text: '[Attachment]', html: '[Attachment]'}; + expect(isReportMessageAttachment(message)).toBe(false); + }); +}); From 8e6cc7f0e7ffb307ab18af9dc112eba054777da2 Mon Sep 17 00:00:00 2001 From: Eric Han <117511920+eh2077@users.noreply.github.com> Date: Mon, 15 May 2023 17:03:18 +0800 Subject: [PATCH 2/2] Update src/libs/isReportMessageAttachment.js Use same regex with backend Co-authored-by: Daniel Gale-Rosen <5487802+dangrous@users.noreply.github.com> --- src/libs/isReportMessageAttachment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/isReportMessageAttachment.js b/src/libs/isReportMessageAttachment.js index 852dc924fdbb..e3553df5e1de 100644 --- a/src/libs/isReportMessageAttachment.js +++ b/src/libs/isReportMessageAttachment.js @@ -8,6 +8,6 @@ import CONST from '../CONST'; * @returns {Boolean} */ export default function isReportMessageAttachment({text, html}) { - const regex = new RegExp(` ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="(.+?)"`, 'i'); + const regex = new RegExp(` ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="(.*)"`, 'i'); return text === CONST.ATTACHMENT_MESSAGE_TEXT && !!html.match(regex); }