From b51adf3292b5124cd960726bf03f2f6e7e2239a7 Mon Sep 17 00:00:00 2001 From: Jarkko Linnanvirta Date: Sun, 19 Mar 2023 08:20:38 +0200 Subject: [PATCH] Apply escape_html condition for all escape_txt_for_html() calls. --- ansi_up.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ansi_up.ts b/ansi_up.ts index b0cccad..28067d7 100644 --- a/ansi_up.ts +++ b/ansi_up.ts @@ -188,6 +188,8 @@ class AnsiUp private escape_txt_for_html(txt:string):string { + if (!this._escape_html) + return txt; return txt.replace(/[&<>"']/gm, (str) => { if (str === "&") return "&"; if (str === "<") return "<"; @@ -661,8 +663,7 @@ class AnsiUp if (txt.length === 0) return txt; - if (this._escape_html) - txt = this.escape_txt_for_html(txt); + txt = this.escape_txt_for_html(txt); // If colors not set, default style is used if (!fragment.bold && !fragment.italic && !fragment.underline && fragment.fg === null && fragment.bg === null) @@ -730,8 +731,7 @@ class AnsiUp if (! this._url_whitelist[parts[0]]) return ''; - let result = `${this._escape_html ? this.escape_txt_for_html(pkt.text) : pkt.text}`; - // Escape href="" even if this._escape_html is false, to avoid breaking the in case pkt.url contains a double quote. + let result = `${this.escape_txt_for_html(pkt.text)}`; return result; }