From f8cb806548387fcaaa0eb9635a12a2b6361299b3 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 19 Sep 2023 13:29:44 +0530 Subject: [PATCH] fix: remove trailing spaces before pushing signature (#7935) Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> --- app/javascript/dashboard/helper/editorHelper.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/javascript/dashboard/helper/editorHelper.js b/app/javascript/dashboard/helper/editorHelper.js index 31d070732..52f87c214 100644 --- a/app/javascript/dashboard/helper/editorHelper.js +++ b/app/javascript/dashboard/helper/editorHelper.js @@ -4,13 +4,26 @@ */ export const SIGNATURE_DELIMITER = '--'; +/** + * Remove trailing spaces from each line in a markdown text + * @param {string} markdownText + * @returns + */ +function removeTrailingSpaces(markdownText) { + return markdownText + .split('\n') + .map(line => line.replace(/\s+$/, '')) + .join('\n'); +} + /** * Trim the signature and remove all " \r" from the signature * 1. Trim any extra lines or spaces at the start or end of the string * 2. Converts all \r or \r\n to \f */ export function cleanSignature(signature) { - return signature.trim().replace(/\r\n?/g, '\n'); + const cleaned = signature.trim().replace(/\r\n?/g, '\n'); + return removeTrailingSpaces(cleaned); } /**