From 092e386cf49f2a1450625617da8e0137ed067c3e Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 22 Sep 2021 09:20:38 +0200 Subject: [PATCH] Fix inefficient regex to replace return characters --- HISTORY.md | 5 +++++ src/js/util.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 8c9d1e264..b83799e3f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,11 @@ https://github.com/josdejong/jsoneditor +## not yet published, version 9.5.6 + +- Fix inefficient regex to replace return characters. + + ## 2021-09-01, version 9.5.5 - Fix `setMode` not throwing an exception anymore in case of a parse error diff --git a/src/js/util.js b/src/js/util.js index 9316e5fd0..997785543 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -399,8 +399,8 @@ export function getInnerText (element, buffer) { // text node if (element.nodeValue) { - // remove return characters and the whitespace surrounding return characters - const trimmedValue = element.nodeValue.replace(/\s*\n\s*/g, '') + // remove return characters and the whitespaces surrounding those return characters + const trimmedValue = element.nodeValue.replace(/(\b|^)\s*\n\s*(\b|$)/g, '') if (trimmedValue !== '') { return buffer.flush() + trimmedValue } else {