From: Art Cancro Date: Wed, 24 Nov 2021 16:51:51 +0000 (-0500) Subject: Prettied up the qp encoder function a bit. X-Git-Tag: v941~12 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=cbfc7cad8d29b9fe44e1ff9cb2e167ba08a1dbc3;p=citadel.git Prettied up the qp encoder function a bit. --- diff --git a/webcit-ng/static/js/view_forum.js b/webcit-ng/static/js/view_forum.js index 93772de73..50c6ae896 100644 --- a/webcit-ng/static/js/view_forum.js +++ b/webcit-ng/static/js/view_forum.js @@ -305,10 +305,7 @@ function save_message(div_name, reply_to_msgnum) { // Function to encode data in quoted-printable format -// discuss at: https://locutus.io/php/quoted_printable_encode/ -// original by: Theriault (https://github.com/Theriault) -// improved by: Brett Zamir (https://brett-zamir.me) -// improved by: Theriault (https://github.com/Theriault) +// Written by Theriault and Brett Zamir [https://locutus.io/php/quoted_printable_encode/] function quoted_printable_encode (str) { // eslint-disable-line camelcase const hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] const RFC2045Encode1IN = / \r\n|\r\n|[^!-<>-~ ]/gm @@ -316,11 +313,11 @@ function quoted_printable_encode (str) { // eslint-disable-line camelcase // Encode space before CRLF sequence to prevent spaces from being stripped // Keep hard line breaks intact; CRLF sequences if (sMatch.length > 1) { - return sMatch.replace(' ', '=20') + return sMatch.replace(' ', '=20'); } // Encode matching character - const chr = sMatch.charCodeAt(0) - return '=' + hexChars[((chr >>> 4) & 15)] + hexChars[(chr & 15)] + const chr = sMatch.charCodeAt(0); + return '=' + hexChars[((chr >>> 4) & 15)] + hexChars[(chr & 15)]; } // Split lines to 75 characters; the reason it's 75 and not 76 is because softline breaks are // preceeded by an equal sign; which would be the 76th character. However, if the last line/string @@ -329,13 +326,11 @@ function quoted_printable_encode (str) { // eslint-disable-line camelcase const RFC2045Encode2IN = /.{1,72}(?!\r\n)[^=]{0,3}/g const RFC2045Encode2OUT = function (sMatch) { if (sMatch.substr(sMatch.length - 2) === '\r\n') { - return sMatch + return sMatch; } - return sMatch + '=\r\n' + return sMatch + '=\r\n'; } - str = str - .replace(RFC2045Encode1IN, RFC2045Encode1OUT) - .replace(RFC2045Encode2IN, RFC2045Encode2OUT) + str = str.replace(RFC2045Encode1IN, RFC2045Encode1OUT).replace(RFC2045Encode2IN, RFC2045Encode2OUT); // Strip last softline break return str.substr(0, str.length - 3) }