From 2bcc19d12adca991bed004facf6ea54a3c3cc038 Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Tue, 13 Dec 2022 00:23:12 -0330
Subject: [PATCH 1/8] fix autolinking issue

---
 src/libs/actions/Report.js | 86 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 2 deletions(-)

diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index 082317c9db63..a84eadcad138 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -892,6 +892,76 @@ function deleteReportComment(reportID, reportAction) {
     API.write('DeleteComment', parameters, {optimisticData, successData, failureData});
 }
 
+/**
+ * Extract all links in a markdown comment and returns them in a list.
+ *
+ * @param {String} comment
+ * @returns {Array}
+ */
+const extractLinksInComment = (comment) => {
+    const reg = /\[[^[\]]*\]\(([^()]*)\)/gm;
+    const matches = [...comment.matchAll(reg)];
+    const links = _.map(matches, match => match[1]); // select the group from match
+    return links;
+};
+
+/**
+ * compares two markdown comments and return a list of the links removed in new comment.
+ *
+ * @param {String} oldComment
+ * @param {String} newComment
+ * @returns {Array}
+ */
+const getRemovedLinks = (oldComment, newComment) => {
+    const linksInOld = extractLinksInComment(oldComment);
+    const linksInNew = extractLinksInComment(newComment);
+    return _.difference(linksInOld, linksInNew);
+};
+
+/**
+ * removes links in a markdown comment.
+ * example:
+ *      comment="test [link](https://www.google.com) test",
+ *      links=["https://www.google.com"]
+ * returns: "test link test"
+ * @param {String} comment
+ * @param {Array} links
+ * @returns {String}
+ */
+const removeLinks = (comment, links) => {
+    let commentCopy = comment.slice();
+    links.forEach((link) => {
+        const reg = new RegExp(`\\[([^\\[\\]]*)\\]\\(${link}\\)`, 'gm');
+        const linkMatch = reg.exec(commentCopy);
+        const linkText = linkMatch && linkMatch[1];
+        commentCopy = commentCopy.replace(`[${linkText}](${link})`, linkText);
+    });
+    return commentCopy;
+};
+
+const removeDeletedLinks = (commentWithLinks, links) => {
+    const userDeletedLinks = getRemovedLinks(markdownForOriginalComment, textForNewComment);
+    let commentCopy = commentWithLinks.slice();
+    links.forEach((link) => {
+        const reg = new RegExp(`\\[([^\\[\\]]*)\\]\\(${link}\\)`, 'gm');
+        const linkMatch = reg.exec(commentCopy);
+        const linkText = linkMatch && linkMatch[1];
+        commentCopy = commentCopy.replace(`[${linkText}](${link})`, linkText);
+    });
+    return commentCopy;
+};
+
+const bla = (htmlWithAutoLinks,originalHtml, newCommentText) => {
+    const parser = new ExpensiMark();
+    const markdownWithAutoLinks = parser.htmlToMarkdown(htmlWithAutoLinks);
+    const markdownOriginalComment = parser.htmlToMarkdown(originalHtml);
+
+    const removedLinks = getRemovedLinks(markdownOriginalComment, newCommentText);
+
+    const newMarkdownAfter = removeLinks(markdownWithAutoLinks, removedLinks);
+    return newMarkdownAfter;
+}
+
 /**
  * Saves a new message for a comment. Marks the comment as edited, which will be reflected in the UI.
  *
@@ -904,7 +974,19 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
 
     // Do not autolink if someone explicitly tries to remove a link from message.
     // https://github.com/Expensify/App/issues/9090
-    const htmlForNewComment = parser.replace(textForNewComment, {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')});
+    // https://github.com/Expensify/App/issues/13221
+
+    const htmlWithAutoLinking = parser.replace(textForNewComment); // Will generate html and autolink all links in comment
+
+    // If user purposely removed a link while editing message. then remove it again.
+    const markdownWithAutoLinking = parser.htmlToMarkdown(htmlWithAutoLinking);
+    const markdownForOriginalComment = parser.htmlToMarkdown(originalReportAction.message[0].html);
+
+    const linksRemovedInComment = getRemovedLinks(markdownForOriginalComment, textForNewComment);
+
+    const markdownAfterRemovingLinks = removeLinks(markdownWithAutoLinking, linksRemovedInComment);
+
+    const htmlForNewComment = parser.replace(markdownAfterRemovingLinks, {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')});
 
     //  Delete the comment if it's empty
     if (_.isEmpty(htmlForNewComment)) {
@@ -925,7 +1007,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
             message: [{
                 isEdited: true,
                 html: htmlForNewComment,
-                text: textForNewComment,
+                text: markdownAfterRemovingLinks,
                 type: originalReportAction.message[0].type,
             }],
         },

From ee9db5dee0bdb79e1575fb6d2f4278bb644af94b Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Tue, 13 Dec 2022 00:39:14 -0330
Subject: [PATCH 2/8] add remaining code

---
 src/libs/actions/Report.js | 39 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index a84eadcad138..918aa042d136 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -939,28 +939,23 @@ const removeLinks = (comment, links) => {
     return commentCopy;
 };
 
-const removeDeletedLinks = (commentWithLinks, links) => {
-    const userDeletedLinks = getRemovedLinks(markdownForOriginalComment, textForNewComment);
-    let commentCopy = commentWithLinks.slice();
-    links.forEach((link) => {
-        const reg = new RegExp(`\\[([^\\[\\]]*)\\]\\(${link}\\)`, 'gm');
-        const linkMatch = reg.exec(commentCopy);
-        const linkText = linkMatch && linkMatch[1];
-        commentCopy = commentCopy.replace(`[${linkText}](${link})`, linkText);
-    });
-    return commentCopy;
-};
-
-const bla = (htmlWithAutoLinks,originalHtml, newCommentText) => {
+/**
+ * This function will handle removing only links that were purposely removed by the user while editing.
+ * @param {String} htmlWithAutoLinks the new comment in html after autolinking all the links
+ * @param {Array} originalHtml original html of the comment before editing
+ * @param {String} newCommentText text of the comment after editing.
+ * @returns {String}
+ */
+const handleUserDeletedLinks = (htmlWithAutoLinks, originalHtml, newCommentText) => {
     const parser = new ExpensiMark();
     const markdownWithAutoLinks = parser.htmlToMarkdown(htmlWithAutoLinks);
     const markdownOriginalComment = parser.htmlToMarkdown(originalHtml);
 
     const removedLinks = getRemovedLinks(markdownOriginalComment, newCommentText);
 
-    const newMarkdownAfter = removeLinks(markdownWithAutoLinks, removedLinks);
-    return newMarkdownAfter;
-}
+    const afterRemovingLinks = removeLinks(markdownWithAutoLinks, removedLinks);
+    return afterRemovingLinks;
+};
 
 /**
  * Saves a new message for a comment. Marks the comment as edited, which will be reflected in the UI.
@@ -979,14 +974,8 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
     const htmlWithAutoLinking = parser.replace(textForNewComment); // Will generate html and autolink all links in comment
 
     // If user purposely removed a link while editing message. then remove it again.
-    const markdownWithAutoLinking = parser.htmlToMarkdown(htmlWithAutoLinking);
-    const markdownForOriginalComment = parser.htmlToMarkdown(originalReportAction.message[0].html);
-
-    const linksRemovedInComment = getRemovedLinks(markdownForOriginalComment, textForNewComment);
-
-    const markdownAfterRemovingLinks = removeLinks(markdownWithAutoLinking, linksRemovedInComment);
-
-    const htmlForNewComment = parser.replace(markdownAfterRemovingLinks, {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')});
+    const markdownForNewComment = handleUserDeletedLinks(htmlWithAutoLinking, originalReportAction.message[0].html, textForNewComment);
+    const htmlForNewComment = parser.replace(markdownForNewComment, {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')});
 
     //  Delete the comment if it's empty
     if (_.isEmpty(htmlForNewComment)) {
@@ -1007,7 +996,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
             message: [{
                 isEdited: true,
                 html: htmlForNewComment,
-                text: markdownAfterRemovingLinks,
+                text: markdownForNewComment,
                 type: originalReportAction.message[0].type,
             }],
         },

From 64c91da780faf3676e1d4688d294f31f0179c49e Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Tue, 13 Dec 2022 11:25:10 -0330
Subject: [PATCH 3/8] addrss comments

---
 src/libs/actions/Report.js | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index 918aa042d136..a75d1ae10bbf 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -893,7 +893,7 @@ function deleteReportComment(reportID, reportAction) {
 }
 
 /**
- * Extract all links in a markdown comment and returns them in a list.
+ * Extracts all links in a markdown comment and returns them in a list.
  *
  * @param {String} comment
  * @returns {Array}
@@ -901,12 +901,12 @@ function deleteReportComment(reportID, reportAction) {
 const extractLinksInComment = (comment) => {
     const reg = /\[[^[\]]*\]\(([^()]*)\)/gm;
     const matches = [...comment.matchAll(reg)];
-    const links = _.map(matches, match => match[1]); // select the group from match
+    const links = _.map(matches, match => match[1]); // Element 1 from match is the reg group if exists
     return links;
 };
 
 /**
- * compares two markdown comments and return a list of the links removed in new comment.
+ * Compares two markdown comments and returns a list of the links removed in a new comment.
  *
  * @param {String} oldComment
  * @param {String} newComment
@@ -919,7 +919,7 @@ const getRemovedLinks = (oldComment, newComment) => {
 };
 
 /**
- * removes links in a markdown comment.
+ * Removes the links in a markdown comment.
  * example:
  *      comment="test [link](https://www.google.com) test",
  *      links=["https://www.google.com"]
@@ -930,7 +930,7 @@ const getRemovedLinks = (oldComment, newComment) => {
  */
 const removeLinks = (comment, links) => {
     let commentCopy = comment.slice();
-    links.forEach((link) => {
+    _.forEach(links, (link) => {
         const reg = new RegExp(`\\[([^\\[\\]]*)\\]\\(${link}\\)`, 'gm');
         const linkMatch = reg.exec(commentCopy);
         const linkText = linkMatch && linkMatch[1];
@@ -950,11 +950,8 @@ const handleUserDeletedLinks = (htmlWithAutoLinks, originalHtml, newCommentText)
     const parser = new ExpensiMark();
     const markdownWithAutoLinks = parser.htmlToMarkdown(htmlWithAutoLinks);
     const markdownOriginalComment = parser.htmlToMarkdown(originalHtml);
-
     const removedLinks = getRemovedLinks(markdownOriginalComment, newCommentText);
-
-    const afterRemovingLinks = removeLinks(markdownWithAutoLinks, removedLinks);
-    return afterRemovingLinks;
+    return removeLinks(markdownWithAutoLinks, removedLinks);
 };
 
 /**
@@ -974,7 +971,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
     const htmlWithAutoLinking = parser.replace(textForNewComment); // Will generate html and autolink all links in comment
 
     // If user purposely removed a link while editing message. then remove it again.
-    const markdownForNewComment = handleUserDeletedLinks(htmlWithAutoLinking, originalReportAction.message[0].html, textForNewComment);
+    const markdownForNewComment = handleUserDeletedLinks(htmlWithAutoLinking, lodashGet(originalReportAction, 'message[0].html'), textForNewComment);
     const htmlForNewComment = parser.replace(markdownForNewComment, {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')});
 
     //  Delete the comment if it's empty

From 63a277a5e5a2c98b3dc06aeaf96c6756cf767bc9 Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Tue, 13 Dec 2022 20:19:58 -0330
Subject: [PATCH 4/8] add unit tests

---
 src/libs/actions/Report.js  | 11 ++++-----
 tests/actions/ReportTest.js | 47 +++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index a75d1ae10bbf..615eef32ea1d 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -941,13 +941,13 @@ const removeLinks = (comment, links) => {
 
 /**
  * This function will handle removing only links that were purposely removed by the user while editing.
- * @param {String} htmlWithAutoLinks the new comment in html after autolinking all the links
- * @param {Array} originalHtml original html of the comment before editing
  * @param {String} newCommentText text of the comment after editing.
+* @param {Array} originalHtml original html of the comment before editing
  * @returns {String}
  */
-const handleUserDeletedLinks = (htmlWithAutoLinks, originalHtml, newCommentText) => {
+const handleUserDeletedLinks = (newCommentText, originalHtml) => {
     const parser = new ExpensiMark();
+    const htmlWithAutoLinks = parser.replace(newCommentText);
     const markdownWithAutoLinks = parser.htmlToMarkdown(htmlWithAutoLinks);
     const markdownOriginalComment = parser.htmlToMarkdown(originalHtml);
     const removedLinks = getRemovedLinks(markdownOriginalComment, newCommentText);
@@ -968,10 +968,8 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
     // https://github.com/Expensify/App/issues/9090
     // https://github.com/Expensify/App/issues/13221
 
-    const htmlWithAutoLinking = parser.replace(textForNewComment); // Will generate html and autolink all links in comment
-
     // If user purposely removed a link while editing message. then remove it again.
-    const markdownForNewComment = handleUserDeletedLinks(htmlWithAutoLinking, lodashGet(originalReportAction, 'message[0].html'), textForNewComment);
+    const markdownForNewComment = handleUserDeletedLinks(textForNewComment, lodashGet(originalReportAction, 'message[0].html'));
     const htmlForNewComment = parser.replace(markdownForNewComment, {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')});
 
     //  Delete the comment if it's empty
@@ -1428,6 +1426,7 @@ export {
     broadcastUserIsTyping,
     togglePinnedState,
     editReportComment,
+    handleUserDeletedLinks,
     saveReportActionDraft,
     deleteReportComment,
     getSimplifiedIOUReport,
diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js
index 9f3e8e478ceb..6a105504da29 100644
--- a/tests/actions/ReportTest.js
+++ b/tests/actions/ReportTest.js
@@ -409,4 +409,51 @@ describe('actions/Report', () => {
                 expect(report.lastMessageText).toBe('Current User Comment 2');
             });
     });
+
+    it.only('Should update comment with links properly', () => {
+        /* This test is intended to test verity of scenarios when user edits a comment
+        * We should generate a link when editing a message unless the link was
+        * already in the comment and the user deleted it on purpose.
+        */
+
+        // User edits comment to add link
+        // We should generate link
+        let originalCommentHTML = 'Original Comment';
+        let afterEditCommentText = 'Original Comment www.google.com';
+        let newCommentMarkdown = Report.handleUserDeletedLinks(afterEditCommentText, originalCommentHTML);
+        let expectedOutput = 'Original Comment [www.google.com](https://www.google.com)';
+        expect(newCommentMarkdown).toBe(expectedOutput);
+
+        // User deletes www.google.com link from comment but keeps link text
+        // We should not generate link
+        originalCommentHTML = 'Comment <a href="https://www.google.com" target="_blank">www.google.com</a>';
+        afterEditCommentText = 'Comment www.google.com';
+        newCommentMarkdown = Report.handleUserDeletedLinks(afterEditCommentText, originalCommentHTML);
+        expectedOutput = 'Comment www.google.com';
+        expect(newCommentMarkdown).toBe(expectedOutput);
+
+        // User Delete only () part of link but leaves the []
+        // We should not generate link
+        originalCommentHTML = 'Comment <a href="https://www.google.com" target="_blank">www.google.com</a>';
+        afterEditCommentText = 'Comment [www.google.com]';
+        newCommentMarkdown = Report.handleUserDeletedLinks(afterEditCommentText, originalCommentHTML);
+        expectedOutput = 'Comment [www.google.com]';
+        expect(newCommentMarkdown).toBe(expectedOutput);
+
+        // User Generates multiple links in one edit
+        // We should generate both links
+        originalCommentHTML = 'Comment';
+        afterEditCommentText = 'Comment www.google.com www.facebook.com';
+        newCommentMarkdown = Report.handleUserDeletedLinks(afterEditCommentText, originalCommentHTML);
+        expectedOutput = 'Comment [www.google.com](https://www.google.com) [www.facebook.com](https://www.facebook.com)';
+        expect(newCommentMarkdown).toBe(expectedOutput);
+
+        // Comment has two links but user deletes only one of them
+        // Should not generate link again for the deleted one
+        originalCommentHTML = 'Comment <a href="https://www.google.com" target="_blank">www.google.com</a>  <a href="https://www.facebook.com" target="_blank">www.facebook.com</a>';
+        afterEditCommentText = 'Comment www.google.com  [www.facebook.com](https://www.facebook.com)';
+        newCommentMarkdown = Report.handleUserDeletedLinks(afterEditCommentText, originalCommentHTML);
+        expectedOutput = 'Comment www.google.com  [www.facebook.com](https://www.facebook.com)';
+        expect(newCommentMarkdown).toBe(expectedOutput);
+    });
 });

From 89fd57607902c28f572ce8270215cfa61f87e1da Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Wed, 14 Dec 2022 14:50:07 -0330
Subject: [PATCH 5/8] remove only

---
 tests/actions/ReportTest.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js
index 6a105504da29..afbdd57b448a 100644
--- a/tests/actions/ReportTest.js
+++ b/tests/actions/ReportTest.js
@@ -410,7 +410,7 @@ describe('actions/Report', () => {
             });
     });
 
-    it.only('Should update comment with links properly', () => {
+    it('Should update comment with links properly', () => {
         /* This test is intended to test verity of scenarios when user edits a comment
         * We should generate a link when editing a message unless the link was
         * already in the comment and the user deleted it on purpose.

From 90a79a604e69180e16e02ee80d4e04e5366a72e2 Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Thu, 15 Dec 2022 02:00:24 -0330
Subject: [PATCH 6/8] add code polish based on comments

---
 src/libs/actions/Report.js  | 20 +++++++++-----------
 tests/actions/ReportTest.js | 10 +++++-----
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index 615eef32ea1d..b044bd93b554 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -893,15 +893,15 @@ function deleteReportComment(reportID, reportAction) {
 }
 
 /**
- * Extracts all links in a markdown comment and returns them in a list.
- *
  * @param {String} comment
  * @returns {Array}
  */
-const extractLinksInComment = (comment) => {
+const extractLinksInMarkdownComment = (comment) => {
     const reg = /\[[^[\]]*\]\(([^()]*)\)/gm;
     const matches = [...comment.matchAll(reg)];
-    const links = _.map(matches, match => match[1]); // Element 1 from match is the reg group if exists
+
+    // Element 1 from match is the regex group if it exists which contains the link URLs
+    const links = _.map(matches, match => match[1]);
     return links;
 };
 
@@ -912,9 +912,9 @@ const extractLinksInComment = (comment) => {
  * @param {String} newComment
  * @returns {Array}
  */
-const getRemovedLinks = (oldComment, newComment) => {
-    const linksInOld = extractLinksInComment(oldComment);
-    const linksInNew = extractLinksInComment(newComment);
+const getRemovedMarkdownLinks = (oldComment, newComment) => {
+    const linksInOld = extractLinksInMarkdownComment(oldComment);
+    const linksInNew = extractLinksInMarkdownComment(newComment);
     return _.difference(linksInOld, linksInNew);
 };
 
@@ -942,7 +942,7 @@ const removeLinks = (comment, links) => {
 /**
  * This function will handle removing only links that were purposely removed by the user while editing.
  * @param {String} newCommentText text of the comment after editing.
-* @param {Array} originalHtml original html of the comment before editing
+ * @param {Array} originalHtml original html of the comment before editing
  * @returns {String}
  */
 const handleUserDeletedLinks = (newCommentText, originalHtml) => {
@@ -950,7 +950,7 @@ const handleUserDeletedLinks = (newCommentText, originalHtml) => {
     const htmlWithAutoLinks = parser.replace(newCommentText);
     const markdownWithAutoLinks = parser.htmlToMarkdown(htmlWithAutoLinks);
     const markdownOriginalComment = parser.htmlToMarkdown(originalHtml);
-    const removedLinks = getRemovedLinks(markdownOriginalComment, newCommentText);
+    const removedLinks = getRemovedMarkdownLinks(markdownOriginalComment, newCommentText);
     return removeLinks(markdownWithAutoLinks, removedLinks);
 };
 
@@ -967,8 +967,6 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
     // Do not autolink if someone explicitly tries to remove a link from message.
     // https://github.com/Expensify/App/issues/9090
     // https://github.com/Expensify/App/issues/13221
-
-    // If user purposely removed a link while editing message. then remove it again.
     const markdownForNewComment = handleUserDeletedLinks(textForNewComment, lodashGet(originalReportAction, 'message[0].html'));
     const htmlForNewComment = parser.replace(markdownForNewComment, {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')});
 
diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js
index afbdd57b448a..c66912668813 100644
--- a/tests/actions/ReportTest.js
+++ b/tests/actions/ReportTest.js
@@ -410,11 +410,11 @@ describe('actions/Report', () => {
             });
     });
 
-    it('Should update comment with links properly', () => {
-        /* This test is intended to test verity of scenarios when user edits a comment
-        * We should generate a link when editing a message unless the link was
-        * already in the comment and the user deleted it on purpose.
-        */
+    it('Should properly update comment with links', () => {
+        /* This tests a variety of scenarios when a user edits a comment.
+         * We should generate a link when editing a message unless the link was
+         * already in the comment and the user deleted it on purpose.
+         */
 
         // User edits comment to add link
         // We should generate link

From 6f179705dc5ef1b5b713aec1bf7818eb3ee32f84 Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Fri, 16 Dec 2022 14:30:23 -0330
Subject: [PATCH 7/8] change reg to regex

---
 src/libs/actions/Report.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index f59ff7a72a20..cdc42254e7cf 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -897,8 +897,8 @@ function deleteReportComment(reportID, reportAction) {
  * @returns {Array}
  */
 const extractLinksInMarkdownComment = (comment) => {
-    const reg = /\[[^[\]]*\]\(([^()]*)\)/gm;
-    const matches = [...comment.matchAll(reg)];
+    const regex = /\[[^[\]]*\]\(([^()]*)\)/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 => match[1]);
@@ -931,8 +931,8 @@ const getRemovedMarkdownLinks = (oldComment, newComment) => {
 const removeLinks = (comment, links) => {
     let commentCopy = comment.slice();
     _.forEach(links, (link) => {
-        const reg = new RegExp(`\\[([^\\[\\]]*)\\]\\(${link}\\)`, 'gm');
-        const linkMatch = reg.exec(commentCopy);
+        const regex = new RegExp(`\\[([^\\[\\]]*)\\]\\(${link}\\)`, 'gm');
+        const linkMatch = regex.exec(commentCopy);
         const linkText = linkMatch && linkMatch[1];
         commentCopy = commentCopy.replace(`[${linkText}](${link})`, linkText);
     });

From a76c8c352665229fb8df12a56d60e5312130d887 Mon Sep 17 00:00:00 2001
From: Mark Armanious <markarmanus@gmail.com>
Date: Fri, 16 Dec 2022 15:21:49 -0330
Subject: [PATCH 8/8] change l to L

---
 src/libs/actions/Report.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index cdc42254e7cf..eec536422004 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -972,7 +972,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
 
     const autolinkFilter = {filterRules: _.filter(_.pluck(parser.rules, 'name'), name => name !== 'autolink')};
     const htmlForNewComment = parser.replace(markdownForNewComment, autolinkFilter);
-    const parsedOriginalCommentHTMl = parser.replace(originalCommentHTML, autolinkFilter);
+    const parsedOriginalCommentHTML = parser.replace(originalCommentHTML, autolinkFilter);
 
     //  Delete the comment if it's empty
     if (_.isEmpty(htmlForNewComment)) {
@@ -981,7 +981,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
     }
 
     // Skip the Edit if message is not changed
-    if (parsedOriginalCommentHTMl === htmlForNewComment.trim()) {
+    if (parsedOriginalCommentHTML === htmlForNewComment.trim()) {
         return;
     }
 
