Skip to content

Commit

Permalink
fix: inclusive comparison for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
samh-nl committed Aug 9, 2023
1 parent 588b04d commit b43b1b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,15 +1485,15 @@ function hasReportNameError(report) {
}

/**
* For comments shorter than 10k chars, convert the comment from MD into HTML because that's how it is stored in the database
* For comments shorter than or equal to 10k chars, convert the comment from MD into HTML because that's how it is stored in the database
* For longer comments, skip parsing, but still escape the text, and display plaintext for performance reasons. It takes over 40s to parse a 100k long string!!
*
* @param {String} text
* @returns {String}
*/
function getParsedComment(text) {
const parser = new ExpensiMark();
return text.length < CONST.MAX_MARKUP_LENGTH ? parser.replace(text) : _.escape(text);
return text.length <= CONST.MAX_MARKUP_LENGTH ? parser.replace(text) : _.escape(text);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ const removeLinksFromHtml = (html, links) => {
*/
const handleUserDeletedLinksInHtml = (newCommentText, originalHtml) => {
const parser = new ExpensiMark();
if (newCommentText.length >= CONST.MAX_MARKUP_LENGTH) {
if (newCommentText.length > CONST.MAX_MARKUP_LENGTH) {
return newCommentText;
}
const markdownOriginalComment = parser.htmlToMarkdown(originalHtml).trim();
Expand All @@ -1043,10 +1043,10 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
const htmlForNewComment = handleUserDeletedLinksInHtml(textForNewComment, originalCommentHTML);
const reportComment = parser.htmlToText(htmlForNewComment);

// For comments shorter than 10k chars, convert the comment from MD into HTML because that's how it is stored in the database
// For comments shorter than or equal to 10k chars, convert the comment from MD into HTML because that's how it is stored in the database
// For longer comments, skip parsing and display plaintext for performance reasons. It takes over 40s to parse a 100k long string!!
let parsedOriginalCommentHTML = originalCommentHTML;
if (textForNewComment.length < CONST.MAX_MARKUP_LENGTH) {
if (textForNewComment.length <= CONST.MAX_MARKUP_LENGTH) {
const autolinkFilter = {filterRules: _.filter(_.pluck(parser.rules, 'name'), (name) => name !== 'autolink')};
parsedOriginalCommentHTML = parser.replace(parser.htmlToMarkdown(originalCommentHTML).trim(), autolinkFilter);
}
Expand Down

0 comments on commit b43b1b9

Please sign in to comment.