From f582784822cb849f49a98e5f005a52901225c94f Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Thu, 18 May 2023 12:51:18 -0500 Subject: [PATCH 1/3] fix: use the same regex as used in ExpensiMark.js --- src/libs/actions/Report.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 6a4cd9fe3050..f47ba5b332e6 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -2,6 +2,7 @@ import {InteractionManager} from 'react-native'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; +import {URL_REGEX} from 'expensify-common/lib/Url'; import Onyx from 'react-native-onyx'; import Str from 'expensify-common/lib/str'; import ONYXKEYS from '../../ONYXKEYS'; @@ -902,7 +903,10 @@ function deleteReportComment(reportID, reportAction) { * @returns {Array} */ const extractLinksInMarkdownComment = (comment) => { - const regex = /\[[^[\]]*\]\(([^()]*)\)/gm; + const regex = new RegExp( + `\\[(?:[^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, + 'gm', + ); const matches = [...comment.matchAll(regex)]; // Element 1 from match is the regex group if it exists which contains the link URLs From 5ada812d387d8d03131b77b8e7c2689d88c389f8 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 23 May 2023 13:19:09 -0500 Subject: [PATCH 2/3] fix: expensify-common version change --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index f4ffdac72ef1..0860535f265b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "babel-polyfill": "^6.26.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#77b3790c00be80ec2d3ac3db59c24b9e3ad68eb0", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#68abe48ad71a98604fdbf5e8e960023ed5807ec2", "fbjs": "^3.0.2", "html-entities": "^1.3.1", "htmlparser2": "^7.2.0", @@ -23520,8 +23520,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#77b3790c00be80ec2d3ac3db59c24b9e3ad68eb0", - "integrity": "sha512-aQs6seGToCIxX5LhPH5wUwM4mLWuyp1LkykmJf1gqdHpSJZV1S/oEg/0N0JamF+in6mwxf/mldfIqEqXXIvK/A==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#68abe48ad71a98604fdbf5e8e960023ed5807ec2", + "integrity": "sha512-OhM2d7W++k0RVscwBpl0cvKXp3aZmflVawQ9Ebh2RBTdy98VZUwq2iZyCDISGNyETthqqsRq8vxy2lFQZZ19RA==", "license": "MIT", "dependencies": { "classnames": "2.3.1", @@ -57401,9 +57401,9 @@ } }, "expensify-common": { - "version": "git+ssh://git@github.com/Expensify/expensify-common.git#77b3790c00be80ec2d3ac3db59c24b9e3ad68eb0", - "integrity": "sha512-aQs6seGToCIxX5LhPH5wUwM4mLWuyp1LkykmJf1gqdHpSJZV1S/oEg/0N0JamF+in6mwxf/mldfIqEqXXIvK/A==", - "from": "expensify-common@git+ssh://git@github.com/Expensify/expensify-common.git#77b3790c00be80ec2d3ac3db59c24b9e3ad68eb0", + "version": "git+ssh://git@github.com/Expensify/expensify-common.git#68abe48ad71a98604fdbf5e8e960023ed5807ec2", + "integrity": "sha512-OhM2d7W++k0RVscwBpl0cvKXp3aZmflVawQ9Ebh2RBTdy98VZUwq2iZyCDISGNyETthqqsRq8vxy2lFQZZ19RA==", + "from": "expensify-common@git+ssh://git@github.com/Expensify/expensify-common.git#68abe48ad71a98604fdbf5e8e960023ed5807ec2", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index d9439c609a9e..1fefae74c945 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "babel-polyfill": "^6.26.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#77b3790c00be80ec2d3ac3db59c24b9e3ad68eb0", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#68abe48ad71a98604fdbf5e8e960023ed5807ec2", "fbjs": "^3.0.2", "html-entities": "^1.3.1", "htmlparser2": "^7.2.0", From 5f4a3883feaf2a6b1877fa9dee34a650f3d6d5ef Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 23 May 2023 13:20:28 -0500 Subject: [PATCH 3/3] fix: use of getRemovedMarkdownLinks in expensify-common --- src/libs/actions/Report.js | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index d53505b0c32a..fa3792cbe167 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -2,7 +2,6 @@ import {InteractionManager} from 'react-native'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; -import {URL_REGEX} from 'expensify-common/lib/Url'; import Onyx from 'react-native-onyx'; import Str from 'expensify-common/lib/str'; import ONYXKEYS from '../../ONYXKEYS'; @@ -898,35 +897,6 @@ function deleteReportComment(reportID, reportAction) { API.write('DeleteComment', parameters, {optimisticData, successData, failureData}); } -/** - * @param {String} comment - * @returns {Array} - */ -const extractLinksInMarkdownComment = (comment) => { - const regex = new RegExp( - `\\[(?:[^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, - 'gm', - ); - const matches = [...comment.matchAll(regex)]; - - // Element 1 from match is the regex group if it exists which contains the link URLs - const links = _.map(matches, (match) => Str.sanitizeURL(match[1])); - return links; -}; - -/** - * Compares two markdown comments and returns a list of the links removed in a new comment. - * - * @param {String} oldComment - * @param {String} newComment - * @returns {Array} - */ -const getRemovedMarkdownLinks = (oldComment, newComment) => { - const linksInOld = extractLinksInMarkdownComment(oldComment); - const linksInNew = extractLinksInMarkdownComment(newComment); - return _.difference(linksInOld, linksInNew); -}; - /** * Removes the links in html of a comment. * example: @@ -962,7 +932,7 @@ const handleUserDeletedLinksInHtml = (newCommentText, originalHtml) => { } const markdownOriginalComment = parser.htmlToMarkdown(originalHtml).trim(); const htmlForNewComment = parser.replace(newCommentText); - const removedLinks = getRemovedMarkdownLinks(markdownOriginalComment, newCommentText); + const removedLinks = parser.getRemovedMarkdownLinks(markdownOriginalComment, newCommentText); return removeLinksFromHtml(htmlForNewComment, removedLinks); };