Skip to content

Commit

Permalink
Merge pull request #18766 from eh2077/17289-fix-report-action-is-not-…
Browse files Browse the repository at this point in the history
…attachment
  • Loading branch information
dangrous authored May 15, 2023
2 parents 5743b15 + 8e6cc7f commit 439d97f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libs/isReportMessageAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
22 changes: 22 additions & 0 deletions tests/unit/isReportMessageAttachmentTest.js
Original file line number Diff line number Diff line change
@@ -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: '<img src="https://www.expensify.com/chat-attachments/1260926113061804740/w_66791ca35b3c34c2a0eda4d065d97c9907cadd61.jpg.1024.jpg" data-expensify-source="https://www.expensify.com/chat-attachments/1260926113061804740/w_66791ca35b3c34c2a0eda4d065d97c9907cadd61.jpg" data-name="rn_image_picker_lib_temp_636b71a8-18fd-41a1-9725-6587ffb207a7.jpg" data-expensify-width="4000" data-expensify-height="3000" />',
};
expect(isReportMessageAttachment(message)).toBe(true);
});

it('returns false if a report action is not attachment', () => {
let message = {text: '[Attachment]', html: '<em>[Attachment]</em>'};
expect(isReportMessageAttachment(message)).toBe(false);

message = {text: '[Attachment]', html: '<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">[Attachment]</a>'};
expect(isReportMessageAttachment(message)).toBe(false);

message = {text: '[Attachment]', html: '<a href="https://www.google.com/?data-expensify-source=" target="_blank" rel="noreferrer noopener">[Attachment]</a>'};
expect(isReportMessageAttachment(message)).toBe(false);
});
});

0 comments on commit 439d97f

Please sign in to comment.