Skip to content

Commit 3fe4df1

Browse files
authored
Merge pull request #902 from Expensify/jsenyitko-expensimark-improvements
[NO QA] Prevent parsing HTML or running expensive ops when there is an empty string
2 parents e9fa45e + e91f407 commit 3fe4df1

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lib/ExpensiMark.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,10 @@ export default class ExpensiMark {
951951
* If not provided, all available rules will be applied. If provided, the rules in the array will be skipped.
952952
*/
953953
replace(text: string, {filterRules = [], shouldEscapeText = true, shouldKeepRawInput = false, disabledRules = [], extras = EXTRAS_DEFAULT}: ReplaceOptions = {}): string {
954+
if (!text) {
955+
return '';
956+
}
957+
954958
// This ensures that any html the user puts into the comment field shows as raw html
955959
let replacedText = shouldEscapeText ? Utils.escapeText(text) : text;
956960
const rules = this.getHtmlRuleset(filterRules, disabledRules, shouldKeepRawInput);
@@ -1232,6 +1236,10 @@ export default class ExpensiMark {
12321236
* Replaces HTML with markdown
12331237
*/
12341238
htmlToMarkdown(htmlString: string, extras: Extras = EXTRAS_DEFAULT): string {
1239+
if (!htmlString) {
1240+
return '';
1241+
}
1242+
12351243
let generatedMarkdown = htmlString;
12361244
const body = /<(body)(?:"[^"]*"|'[^']*'|[^'"><])*>(?:\n|\r\n)?([\s\S]*?)(?:\n|\r\n)?<\/\1>(?![^<]*(<\/pre>|<\/code>))/im;
12371245
const parseBodyTag = generatedMarkdown.match(body);

0 commit comments

Comments
 (0)